Skip to content

Instantly share code, notes, and snippets.

@vvvvalvalval
Created November 18, 2016 09:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vvvvalvalval/4e5e5174e6ab5baadfb92a0abce6b679 to your computer and use it in GitHub Desktop.
Save vvvvalvalval/4e5e5174e6ab5baadfb92a0abce6b679 to your computer and use it in GitHub Desktop.
utility for knowing what other branches will be merged if you merge a git branch into another
#!/usr/bin/env node
var br1 = process.argv[2];
var br2 = process.argv[3];
var exec = require('child_process').exec;
function setDiff(s1, s2){
return s1.filter(function(e){
return s2.indexOf(e) < 0;
});
}
function parseBranches(stdout){
return stdout.split(/[\r\n\s\*]+/).filter(function(brName){
return brName !== '';
});
}
function p_mergedIn(br){
return new Promise(function(res, rej){
exec('git branch --merged ' + br, function(err, stdout, stderr){
if(err){
rej(err);
} else {
res(stdout);
}
});
}).then(parseBranches);
}
function printSet(s){
s.sort().forEach(function(e){
console.log(e);
})
}
Promise.all([p_mergedIn(br1),p_mergedIn(br2)]).then(function(arr){
return (function(branches1, branches2){
return setDiff(branches1, branches2);
}).apply(null, arr)
}).then(printSet);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment