Merge branch 'gt9-no-done-no-clean'
This commit is contained in:
commit
5fc32f831a
@ -3,7 +3,7 @@ const u = require("updeep");
|
||||
const _ = require("lodash");
|
||||
const fp = require("lodash/fp");
|
||||
|
||||
const log = require('./log');
|
||||
const log = require("./log");
|
||||
|
||||
const normalizeArray = (value) =>
|
||||
Array.isArray(value) ? value : [value].filter((x) => x);
|
||||
@ -16,12 +16,14 @@ const initBranch = (config = {}) => ({
|
||||
|
||||
const git = Git();
|
||||
|
||||
const currentBranch = _.once(() =>git
|
||||
.raw("branch", "--show-current")
|
||||
.then((r) => r.replace("\n", "")));
|
||||
const currentBranch = _.once(() =>
|
||||
git.raw("branch", "--show-current").then((r) => r.replace("\n", ""))
|
||||
);
|
||||
|
||||
const isClean = () => git.status().then(({ files }) => !files.length);
|
||||
|
||||
const branches = _.once(async () => {
|
||||
const config = await git.listConfig("local").then(fp.get('all'));
|
||||
const config = await git.listConfig("local").then(fp.get("all"));
|
||||
|
||||
let tree = Object.entries(config).reduce(
|
||||
(accum, [key, value]) => u.updateIn(key, value, accum),
|
||||
@ -58,9 +60,12 @@ const branches = _.once(async () => {
|
||||
|
||||
// include the merged info
|
||||
for (const branch of Object.values(branches)) {
|
||||
branch.contains = _.compact(await git.raw( 'branch', '--merged', branch.name )
|
||||
.then( r => r.replace( /[ *]/g, '' ) )
|
||||
.then( r => r.split("\n") ))
|
||||
branch.contains = _.compact(
|
||||
await git
|
||||
.raw("branch", "--merged", branch.name)
|
||||
.then((r) => r.replace(/[ *]/g, ""))
|
||||
.then((r) => r.split("\n"))
|
||||
);
|
||||
}
|
||||
|
||||
const current = await currentBranch();
|
||||
@ -73,43 +78,41 @@ const branches = _.once(async () => {
|
||||
async function canBeDeleted() {
|
||||
const allBranches = await branches();
|
||||
|
||||
return Object.values(allBranches).filter(
|
||||
fp.get('done')
|
||||
).filter( ({name,upstream})=>
|
||||
upstream.every( u => allBranches[u].contains.includes(name) )
|
||||
).map(fp.get('name'));
|
||||
|
||||
return Object.values(allBranches)
|
||||
.filter(fp.get("done"))
|
||||
.filter(({ name, upstream }) =>
|
||||
upstream.every((u) => allBranches[u].contains.includes(name))
|
||||
)
|
||||
.map(fp.get("name"));
|
||||
}
|
||||
|
||||
async function canBeWorkedOn() {
|
||||
const allBranches = await branches();
|
||||
|
||||
return Object.values(allBranches).filter(
|
||||
({done}) => !done
|
||||
).filter( ({name,dependencies})=>
|
||||
dependencies.every( u => allBranches[u].done )
|
||||
).map(fp.get('name'));
|
||||
|
||||
return Object.values(allBranches)
|
||||
.filter(({ done }) => !done)
|
||||
.filter(({ name, dependencies }) =>
|
||||
dependencies.every((u) => allBranches[u].done)
|
||||
)
|
||||
.map(fp.get("name"));
|
||||
}
|
||||
|
||||
async function needsRebasing() {
|
||||
const allBranches = await branches();
|
||||
|
||||
return Object.values(allBranches).filter(
|
||||
fp.get('base')
|
||||
).filter( ({base,name})=>
|
||||
!allBranches[name].contains.includes(base)
|
||||
).map(fp.get('name'));
|
||||
|
||||
return Object.values(allBranches)
|
||||
.filter(fp.get("base"))
|
||||
.filter(({ base, name }) => !allBranches[name].contains.includes(base))
|
||||
.map(fp.get("name"));
|
||||
}
|
||||
|
||||
async function needsMerging() {
|
||||
const allBranches = await branches();
|
||||
|
||||
return Object.values(allBranches).filter(
|
||||
fp.get('done')
|
||||
).flatMap( ({upstream,name})=> upstream.map( u => [ name, u ] ) )
|
||||
.filter( ([name,up]) => !allBranches[up].contains.includes(name) )
|
||||
return Object.values(allBranches)
|
||||
.filter(fp.get("done"))
|
||||
.flatMap(({ upstream, name }) => upstream.map((u) => [name, u]))
|
||||
.filter(([name, up]) => !allBranches[up].contains.includes(name));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
@ -119,4 +122,5 @@ module.exports = {
|
||||
canBeWorkedOn,
|
||||
needsRebasing,
|
||||
needsMerging,
|
||||
isClean,
|
||||
};
|
||||
|
@ -1,15 +1,20 @@
|
||||
const Git = require('simple-git');
|
||||
const inquirer = require('inquirer');
|
||||
const report = require('yurnalist');
|
||||
const _ = require('lodash');
|
||||
const { currentBranch } = require( '../utils');
|
||||
const Git = require("simple-git");
|
||||
const inquirer = require("inquirer");
|
||||
const report = require("yurnalist");
|
||||
const _ = require("lodash");
|
||||
|
||||
const myGit = require("../branches");
|
||||
const log = require("../log");
|
||||
|
||||
module.exports = async (yargs) => {
|
||||
if (!(await myGit.isClean())) {
|
||||
log.error("workspace not clean, aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
const current = await currentBranch();
|
||||
const current = await myGit.currentBranch();
|
||||
|
||||
console.log(`marking branch '${current}' as done`);
|
||||
log.success(`W00t! marking branch '${current}' as done`);
|
||||
|
||||
await Git().addConfig(`branch.${current}.mikado-done`, true);
|
||||
|
||||
}
|
||||
};
|
||||
|
@ -7,8 +7,8 @@ const u = require("updeep");
|
||||
const columnify = require("columnify");
|
||||
const chalk = require("chalk");
|
||||
|
||||
const myGit = require('../branches');
|
||||
const log = require('../log');
|
||||
const myGit = require("../branches");
|
||||
const log = require("../log");
|
||||
|
||||
const iconFor = (branch, branches) => {
|
||||
if (branch.done) return "✅";
|
||||
@ -18,25 +18,22 @@ const iconFor = ( branch, branches ) => {
|
||||
}
|
||||
|
||||
return "🙋";
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
const decorateCurrent = async branch => {
|
||||
if( branch !== await myGit.currentBranch() ) return branch;
|
||||
const decorateCurrent = async (branch) => {
|
||||
if (branch !== (await myGit.currentBranch())) return branch;
|
||||
|
||||
return chalk.underline.bold(branch);
|
||||
}
|
||||
};
|
||||
|
||||
async function printNeedsRebasing() {
|
||||
const needsRebasing = await myGit.needsRebasing();
|
||||
|
||||
if (!needsRebasing.length) return false;
|
||||
|
||||
log.subtitle(':arrow_heading_up: needs rebasing');
|
||||
const b = await Promise.all(
|
||||
needsRebasing.map( decorateCurrent )
|
||||
);
|
||||
log.info( "\t", b.join(', ') );
|
||||
log.subtitle(":arrow_heading_up: needs rebasing");
|
||||
const b = await Promise.all(needsRebasing.map(decorateCurrent));
|
||||
log.info("\t", b.join(", "));
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -46,31 +43,29 @@ async function printNeedsMerging() {
|
||||
|
||||
if (!needsMerging.length) return false;
|
||||
|
||||
log.subtitle(':thumbsup: ready to be merged');
|
||||
log.info( "\t", needsMerging.map( x => x.join('->') ).join(', ') );
|
||||
log.subtitle(":thumbsup: ready to be merged");
|
||||
log.info("\t", needsMerging.map((x) => x.join("->")).join(", "));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
async function printActionables() {
|
||||
|
||||
log.title(":point_right: What's next?");
|
||||
|
||||
let something = false;
|
||||
const accumSomething = (value) => something ||= value;
|
||||
|
||||
accumSomething( await printNeedsRebasing() );
|
||||
const accumSomething = (value) => (something ||= value);
|
||||
|
||||
accumSomething(await printNeedsMerging());
|
||||
|
||||
accumSomething(await printNeedsRebasing());
|
||||
|
||||
const canBeDeleted = await myGit.canBeDeleted();
|
||||
|
||||
if (canBeDeleted.length) {
|
||||
something = true;
|
||||
|
||||
log.subtitle(':recycle: branches that can be deleted');
|
||||
log.info( "\t", canBeDeleted.join(', ') );
|
||||
log.subtitle(":recycle: branches that can be deleted");
|
||||
log.info("\t", canBeDeleted.join(", "));
|
||||
}
|
||||
|
||||
const canBeWorkedOn = await myGit.canBeWorkedOn();
|
||||
@ -78,17 +73,14 @@ async function printActionables() {
|
||||
if (canBeWorkedOn.length) {
|
||||
something = true;
|
||||
|
||||
log.subtitle(':hammer: ready to be worked on');
|
||||
const b = await Promise.all(
|
||||
canBeWorkedOn.map( decorateCurrent )
|
||||
);
|
||||
log.info( "\t", b.join(', ') );
|
||||
log.subtitle(":hammer: ready to be worked on");
|
||||
const b = await Promise.all(canBeWorkedOn.map(decorateCurrent));
|
||||
log.info("\t", b.join(", "));
|
||||
}
|
||||
|
||||
if (!something) {
|
||||
log.info("nothing? :shrug:");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = async () => {
|
||||
@ -98,9 +90,7 @@ module.exports = async () => {
|
||||
let color = branches[dep].done ? chalk.green : chalk.red;
|
||||
|
||||
let contains = await Git().raw("branch", "--contains", dep);
|
||||
contains = contains
|
||||
.split("\n")
|
||||
.map((x) => x.trim().replace("* ", ""));
|
||||
contains = contains.split("\n").map((x) => x.trim().replace("* ", ""));
|
||||
|
||||
if (contains.includes(current)) color = color.underline;
|
||||
|
||||
@ -111,9 +101,7 @@ module.exports = async () => {
|
||||
let color = branches[up].done ? chalk.green : chalk.red;
|
||||
|
||||
let contains = await Git().raw("branch", "--contains", current);
|
||||
contains = contains
|
||||
.split("\n")
|
||||
.map((x) => x.trim().replace("* ", ""));
|
||||
contains = contains.split("\n").map((x) => x.trim().replace("* ", ""));
|
||||
|
||||
if (contains.includes(up)) color = color.underline;
|
||||
|
||||
@ -128,7 +116,7 @@ module.exports = async () => {
|
||||
console.log(
|
||||
iconFor(branch, branches),
|
||||
chalk.blue(branch.name),
|
||||
branch.current ? "👷" : ' '
|
||||
branch.current ? "👷" : " "
|
||||
);
|
||||
console.log(`\tbase: ${chalk.magenta(branch.base ?? "<none>")}`);
|
||||
|
||||
@ -145,9 +133,7 @@ module.exports = async () => {
|
||||
);
|
||||
console.log("\tdependencies:", deps.join(" "));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
await printActionables();
|
||||
|
||||
};
|
||||
|
12
src/log.js
12
src/log.js
@ -1,12 +1,14 @@
|
||||
const emoji = require('node-emoji');
|
||||
const emoji = require("node-emoji");
|
||||
const chalk = require("chalk");
|
||||
|
||||
function groomLog(...entries) {
|
||||
console.log( ...(entries.map(emoji.emojify)) );
|
||||
console.log(...entries.map(emoji.emojify));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
info: groomLog,
|
||||
title: title => groomLog("\n",chalk.blue.bold(title)),
|
||||
subtitle: title => groomLog("\n",chalk.blue(title)),
|
||||
}
|
||||
title: (title) => groomLog("\n", chalk.blue.bold(title)),
|
||||
subtitle: (title) => groomLog("\n", chalk.blue(title)),
|
||||
error: (message) => groomLog(":skull:", chalk.red(message)),
|
||||
success: (message) => groomLog(":sparkles:", chalk.green(message)),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user