Return more detailed information on /project/branches api

This commit is contained in:
Nick O'Leary
2017-12-07 22:24:57 +00:00
parent 3adfe249b0
commit d007623347
3 changed files with 32 additions and 23 deletions

View File

@@ -272,17 +272,35 @@ function getRemotes(cwd) {
}
function getBranches(cwd, remote) {
var args = ['branch','--no-color'];
var args = ['branch','-vv','--no-color'];
if (remote) {
args.push('-r');
}
//TODO: parse out ahead/behind status (currently m[5] vvv )
var branchRE = /^([ \*] )(\S+) +(\S+)(?: \[(\S+?)(?:: (.*))?\])? (.*)$/;
return runGitCommand(args,cwd).then(function(output) {
var branches = [];
var lines = output.split("\n");
branches = lines.map(function(l) { return l.substring(2)})
.filter(function(l) {
return !/HEAD ->/.test(l) && (l.length > 0)
});
branches = lines.map(function(l) {
var m = branchRE.exec(l);
var branch = null;
if (m) {
branch = {
name: m[2],
remote: m[4],
status: m[5],
commit: {
sha: m[3],
subject: m[6]
}
}
if (m[1] === '* ') {
branch.current = true;
}
}
return branch;
}).filter(function(v) { return !!v && v.commit.sha !== '->' });
return {branches:branches};
})
}