wip
This commit is contained in:
parent
bf32c59770
commit
d389a4f9b6
11
package.json
11
package.json
@ -10,12 +10,11 @@
|
||||
"author": "Yanick Champoux <yanick@babyl.ca> (http://techblog.babyl.ca)",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@types/inquirer": "^7.3.1",
|
||||
"@types/node": "^14.14.16",
|
||||
"@types/yargs": "^15.0.12",
|
||||
"@gitgraph/node": "^0.1.18",
|
||||
"inquirer": "^7.3.3",
|
||||
"simple-git": "^2.31.0",
|
||||
"typescript": "^4.1.3",
|
||||
"yargs": "^16.2.0"
|
||||
"lodash": "^4.17.21",
|
||||
"simple-git": "^2.47.0",
|
||||
"yargs": "^16.2.0",
|
||||
"yurnalist": "^2.1.0"
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,65 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = (function () {
|
||||
console.log('yay');
|
||||
});
|
||||
const Git = require('simple-git');
|
||||
const inquirer = require('inquirer');
|
||||
const report = require('yurnalist');
|
||||
const _ = require('lodash');
|
||||
|
||||
async function checkWorkspaceClean() {
|
||||
return Git().status().then((result) => {
|
||||
if (!result.isClean()) throw new Error('workspace not clean, aborting');
|
||||
})
|
||||
}
|
||||
|
||||
async function currentBranch() {
|
||||
let branch = await Git().raw('branch', '--show-current');
|
||||
return branch.replace("\n",'');
|
||||
}
|
||||
|
||||
async function getBaseBranch(branch) {
|
||||
|
||||
const base = await Git().getConfig(`branch.${branch}.mikado-base`);
|
||||
|
||||
if(base.value) return base.value;
|
||||
|
||||
// not in the config? Okay then, let's see all the
|
||||
// options we have
|
||||
const result = await Git().branch({'--merged': 'HEAD'});
|
||||
|
||||
const answer = await inquirer.prompt([
|
||||
{
|
||||
name: 'base',
|
||||
message: 'base branch: ',
|
||||
type: 'list',
|
||||
choices: result.all,
|
||||
}
|
||||
]);
|
||||
|
||||
return answer.base;
|
||||
}
|
||||
|
||||
module.exports = async (yargs) => {
|
||||
|
||||
// await checkWorkspaceClean();
|
||||
|
||||
const branch = yargs.branch;
|
||||
|
||||
const upstream = await currentBranch();
|
||||
|
||||
const base = yargs.base ?? await getBaseBranch(upstream);
|
||||
|
||||
report.list('setup', ['branch','upstream','base'],{
|
||||
branch,
|
||||
upstream,
|
||||
base,
|
||||
});
|
||||
|
||||
report.info(`branching ${branch} off ${base}`);
|
||||
|
||||
await Git().checkoutBranch(branch,base);
|
||||
|
||||
await Git().addConfig( `branch.${branch}.mikado-base`, base );
|
||||
await Git().addConfig( `branch.${branch}.mikado-upstream`, upstream );
|
||||
|
||||
await Git().addConfig( `branch.${upstream}.mikado-dependency`, branch, true );
|
||||
|
||||
report.success('done!');
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
import Git from 'simple-git';
|
||||
import inquirer from 'inquirer';
|
||||
|
||||
async function check_workspace_clean() {
|
||||
return Git().status().then((result) => {
|
||||
if (!result.isClean()) throw new Error('workspace not clean, aborting');
|
||||
})
|
||||
}
|
||||
|
||||
export default async () => {
|
||||
await check_workspace_clean();
|
||||
|
||||
const result = await Git().branch({'--merged': 'HEAD'});
|
||||
|
||||
const ancestors = result.all;
|
||||
|
||||
const resp = await inquirer.prompt([
|
||||
{
|
||||
name: 'parent',
|
||||
message: 'grand-parent branch: ',
|
||||
type: 'list',
|
||||
choices: ancestors,
|
||||
}
|
||||
])
|
||||
|
||||
console.log(resp);
|
||||
}
|
@ -1,11 +1,38 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var yargs_1 = __importDefault(require("yargs"));
|
||||
var new_branch_1 = __importDefault(require("./commands/new_branch"));
|
||||
yargs_1.default(process.argv.slice(2))
|
||||
.command('new [branch_name]', 'create new mikado branch', function (yargs) {
|
||||
yargs.positional('branch_name', { describe: 'name of the new branch', required: true });
|
||||
}, new_branch_1.default).argv;
|
||||
const yargs = require("yargs");
|
||||
const new_branch = require("./commands/new_branch");
|
||||
|
||||
yargs
|
||||
.scriptName("git-mikado")
|
||||
.showHelpOnFail(true)
|
||||
.command(
|
||||
"new [branch]",
|
||||
"create new mikado branch",
|
||||
(yargs) => {
|
||||
return yargs
|
||||
.positional("branch", {
|
||||
describe: "name of the new branch",
|
||||
})
|
||||
.option("base", {
|
||||
alias: "b",
|
||||
describe: "base branch",
|
||||
})
|
||||
.option("upstream", {
|
||||
alias: "u",
|
||||
describe: "branch that is dependent on the new branch",
|
||||
})
|
||||
.demandOption(["branch"]);
|
||||
},
|
||||
new_branch
|
||||
)
|
||||
.fail((msg, err, yargs) => {
|
||||
try {
|
||||
const message = msg || err.message;
|
||||
console.error(message);
|
||||
process.exit(1);
|
||||
} catch (e) {
|
||||
yargs.showHelp();
|
||||
}
|
||||
})
|
||||
.help()
|
||||
.demandCommand(1, "")
|
||||
.strict().argv;
|
||||
|
@ -1,16 +0,0 @@
|
||||
import yargs from 'yargs';
|
||||
|
||||
import new_branch from './commands/new_branch'
|
||||
|
||||
yargs(process.argv.slice(2))
|
||||
.command( 'new [branch_name]', 'create new mikado branch', yargs => {
|
||||
yargs.positional('branch_name', {describe: 'name of the new branch', required: true} )
|
||||
},
|
||||
new_branch
|
||||
)
|
||||
.fail((msg,err,yargs) => {
|
||||
const message = msg || err.message;
|
||||
console.error(message);
|
||||
process.exit(1);
|
||||
})
|
||||
.argv;
|
Loading…
Reference in New Issue
Block a user