-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
38 lines (35 loc) · 1.24 KB
/
main.js
File metadata and controls
38 lines (35 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env node
const program = require('commander');
const R = require('ramda');
const exec = require('child_process').exec;
const tree = require('./src/tree');
const diffStrToChanges = require('./src/diffStrToChanges');
const drawTree = require('./src/drawTree');
const print = require('./src/print');
const interactive = require('./src/interactive');
const execDiffandDrawTree = (branchA, branchB) => {
exec(`git diff --name-status --no-renames ${branchA}...${branchB}`, (err, stdout, stderr) => {
const changes = diffStrToChanges(stdout);
const treeData = tree(changes);
console.log(drawTree(treeData));
});
};
program
.usage('[options] [branchA [branchB]]')
.option('-i --interactive', 'Interactive mode', false)
.parse(process.argv);
if (program.interactive) {
console.log('do interactive');
interactive(execDiffandDrawTree);
} else {
const diffAgainstBranch = R.defaultTo('master', program.args[0]);
if (program.args.length <= 1) {
exec('git symbolic-ref --short HEAD', (err, stdout, stderr) => {
const checkedOutBranch = stdout.trim();
execDiffandDrawTree(diffAgainstBranch, checkedOutBranch);
});
} else {
const branchB = program.args[1];
execDiffandDrawTree(diffAgainstBranch, branchB);
}
}