1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

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
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 32 additions and 23 deletions

View File

@ -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 = $('<div class="projects-branch-list">').appendTo(options.container);
@ -882,15 +881,15 @@ RED.projects = (function() {
scrollOnAdd: false,
addItem: function(row,index,entry) {
var container = $('<div class="sidebar-version-control-branch-list-entry">').appendTo(row);
if (typeof entry !== "string") {
if (!entry.hasOwnProperty('commit')) {
branchFilterCreateItem = container;
$('<i class="fa fa-code-fork"></i>').appendTo(container);
$('<span>').text("Create branch:").appendTo(container);
$('<div class="sidebar-version-control-branch-list-entry-create-name" style="margin-left: 10px;">').text(entry.name).appendTo(container);
} else {
$('<i class="fa fa-code-fork"></i>').appendTo(container);
$('<span>').text(entry).appendTo(container);
if (currentBranch === entry) {
$('<span>').text(entry.name).appendTo(container);
if (entry.current) {
container.addClass("selected");
$('<span class="current"></span>').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() }
}

View File

@ -571,9 +571,6 @@ RED.sidebar.versionControl = (function() {
$('<div class="sidebar-version-control-slide-box-header"></div>').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 = $('<div style="height: 0;overflow:hidden; transition: height 0.2s ease-in-out;"></div>').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() {

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};
})
}