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)",
|
"author": "Yanick Champoux <yanick@babyl.ca> (http://techblog.babyl.ca)",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/inquirer": "^7.3.1",
|
"@gitgraph/node": "^0.1.18",
|
||||||
"@types/node": "^14.14.16",
|
|
||||||
"@types/yargs": "^15.0.12",
|
|
||||||
"inquirer": "^7.3.3",
|
"inquirer": "^7.3.3",
|
||||||
"simple-git": "^2.31.0",
|
"lodash": "^4.17.21",
|
||||||
"typescript": "^4.1.3",
|
"simple-git": "^2.47.0",
|
||||||
"yargs": "^16.2.0"
|
"yargs": "^16.2.0",
|
||||||
|
"yurnalist": "^2.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,65 @@
|
|||||||
"use strict";
|
const Git = require('simple-git');
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
const inquirer = require('inquirer');
|
||||||
exports.default = (function () {
|
const report = require('yurnalist');
|
||||||
console.log('yay');
|
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";
|
const yargs = require("yargs");
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
const new_branch = require("./commands/new_branch");
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
||||||
};
|
yargs
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
.scriptName("git-mikado")
|
||||||
var yargs_1 = __importDefault(require("yargs"));
|
.showHelpOnFail(true)
|
||||||
var new_branch_1 = __importDefault(require("./commands/new_branch"));
|
.command(
|
||||||
yargs_1.default(process.argv.slice(2))
|
"new [branch]",
|
||||||
.command('new [branch_name]', 'create new mikado branch', function (yargs) {
|
"create new mikado branch",
|
||||||
yargs.positional('branch_name', { describe: 'name of the new branch', required: true });
|
(yargs) => {
|
||||||
}, new_branch_1.default).argv;
|
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