diff --git a/editor/js/ui/projects.js b/editor/js/ui/projects.js index 0493bad0a..903ead70b 100644 --- a/editor/js/ui/projects.js +++ b/editor/js/ui/projects.js @@ -581,7 +581,7 @@ RED.projects = (function() { } } ] - + } } } @@ -852,7 +852,6 @@ RED.projects = (function() { var branchFilterTerm = ""; var branchFilterCreateItem; var branches = []; - var currentBranch; var branchPrefix = ""; var container = $('
').appendTo(options.container); @@ -882,15 +881,15 @@ RED.projects = (function() { scrollOnAdd: false, addItem: function(row,index,entry) { var container = $('
').appendTo(row); - if (typeof entry !== "string") { + if (!entry.hasOwnProperty('commit')) { branchFilterCreateItem = container; $('').appendTo(container); $('').text("Create branch:").appendTo(container); $('
').text(entry.name).appendTo(container); } else { $('').appendTo(container); - $('').text(entry).appendTo(container); - if (currentBranch === entry) { + $('').text(entry.name).appendTo(container); + if (entry.current) { container.addClass("selected"); $('').text(options.currentLabel||"current").appendTo(container); } @@ -901,7 +900,7 @@ RED.projects = (function() { return; } var body = {}; - if (typeof entry !== "string") { + if (!entry.hasOwnProperty('commit')) { body.name = branchFilter.val(); body.create = true; if (options.remote) { @@ -911,7 +910,7 @@ RED.projects = (function() { if ($(this).hasClass('selected')) { body.current = true; } - body.name = entry; + body.name = entry.name; } if (options.onselect) { options.onselect(body); @@ -919,7 +918,7 @@ RED.projects = (function() { }); }, filter: function(data) { - var isCreateEntry = (typeof data !=="string"); + var isCreateEntry = (!data.hasOwnProperty('commit')); return ( isCreateEntry && ( @@ -929,7 +928,7 @@ RED.projects = (function() { ) || ( !isCreateEntry && - data.indexOf(branchFilterTerm) !== -1 + data.name.indexOf(branchFilterTerm) !== -1 ); } }); @@ -939,14 +938,12 @@ RED.projects = (function() { branchList.editableList('empty'); var start = Date.now(); var spinner = addSpinnerOverlay(container).addClass("projects-dialog-spinner-contain"); - currentBranch = options.current(); if (options.remote) { branchPrefix = options.remote()+"/"; } else { branchPrefix = ""; } - sendRequest({ url: url, type: "GET", @@ -972,7 +969,7 @@ RED.projects = (function() { } }) }, - addItem: function(data) { branchList.editableList('addItem',data) }, + // addItem: function(data) { branchList.editableList('addItem',data) }, filter: function() { branchList.editableList('filter') }, focus: function() { branchFilter.focus() } } diff --git a/editor/js/ui/tab-versionControl.js b/editor/js/ui/tab-versionControl.js index eefb7e2ba..0c97ca24c 100644 --- a/editor/js/ui/tab-versionControl.js +++ b/editor/js/ui/tab-versionControl.js @@ -571,9 +571,6 @@ RED.sidebar.versionControl = (function() { $('').text("Change local branch").appendTo(localBranchBox); var localBranchList = utils.createBranchList({ - current: function() { - return RED.projects.getActiveProject().git.branches.local - }, placeholder: "Find or create a branch", container: localBranchBox, onselect: function(body) { @@ -711,9 +708,6 @@ RED.sidebar.versionControl = (function() { var remoteBranchSubRow = $('
').hide().appendTo(remoteBranchRow); var remoteBranchList = utils.createBranchList({ - current: function() { - return RED.projects.getActiveProject().git.branches.remote - }, placeholder: "Find or create a remote branch", currentLabel: "upstream", remote: function() { diff --git a/red/runtime/storage/localfilesystem/projects/git/index.js b/red/runtime/storage/localfilesystem/projects/git/index.js index 2152390e4..96eef3c3a 100644 --- a/red/runtime/storage/localfilesystem/projects/git/index.js +++ b/red/runtime/storage/localfilesystem/projects/git/index.js @@ -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}; }) }