Created
November 18, 2016 09:25
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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