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

[projects] Allow remote branch dialog to create non-default remote branches

This commit is contained in:
Nick O'Leary 2020-05-21 17:19:54 +01:00
parent 8ce49c25d4
commit ad78ce0eb6
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 39 additions and 13 deletions

View File

@ -2087,6 +2087,8 @@ RED.projects = (function() {
var branchFilterTerm = ""; var branchFilterTerm = "";
var branchFilterCreateItem; var branchFilterCreateItem;
var branches = []; var branches = [];
var branchNames = new Set();
var remotes = [];
var branchPrefix = ""; var branchPrefix = "";
var container = $('<div class="red-ui-projects-branch-list">').appendTo(options.container); var container = $('<div class="red-ui-projects-branch-list">').appendTo(options.container);
@ -2094,18 +2096,30 @@ RED.projects = (function() {
delay: 200, delay: 200,
change: function() { change: function() {
branchFilterTerm = $(this).val(); branchFilterTerm = $(this).val();
if (/(\.\.|\/\.|[?*[~^: \\]|\/\/|\/.$|\/$)/.test(branchFilterTerm)) { // if there is a / then
// - check what preceeds it is a known remote
var valid = false;
var hasRemote = false;
var m = /^([^/]+)\/[^/.~*?\[]/.exec(branchFilterTerm);
if (m && remotes.indexOf(m[1]) > -1) {
valid = true;
hasRemote = true;
}
if (!valid && /(\.\.|\/\.|[?*[~^: \\]|\/\/|\/.$|\/$)/.test(branchFilterTerm)) {
if (!branchFilterCreateItem.hasClass("input-error")) { if (!branchFilterCreateItem.hasClass("input-error")) {
branchFilterCreateItem.addClass("input-error"); branchFilterCreateItem.addClass("input-error");
branchFilterCreateItem.find("i").addClass("fa-warning").removeClass("fa-code-fork"); branchFilterCreateItem.find("i").addClass("fa-warning").removeClass("fa-code-fork");
} }
branchFilterCreateItem.find("span").text(RED._("projects.create-branch-list.invalid")+": "+branchPrefix+branchFilterTerm); branchFilterCreateItem.find("span").text(RED._("projects.create-branch-list.invalid")+": "+(hasRemote?"":branchPrefix)+branchFilterTerm);
} else { } else {
if (branchFilterCreateItem.hasClass("input-error")) { if (branchFilterCreateItem.hasClass("input-error")) {
branchFilterCreateItem.removeClass("input-error"); branchFilterCreateItem.removeClass("input-error");
branchFilterCreateItem.find("i").removeClass("fa-warning").addClass("fa-code-fork"); branchFilterCreateItem.find("i").removeClass("fa-warning").addClass("fa-code-fork");
} }
branchFilterCreateItem.find(".red-ui-sidebar-vc-branch-list-entry-create-name").text(branchPrefix+branchFilterTerm); branchFilterCreateItem.find("span").text(RED._("projects.create-branch-list.create")+":");
branchFilterCreateItem.find(".red-ui-sidebar-vc-branch-list-entry-create-name").text((hasRemote?"":branchPrefix)+branchFilterTerm);
} }
branchList.editableList("filter"); branchList.editableList("filter");
} }
@ -2138,8 +2152,12 @@ RED.projects = (function() {
if (!entry.hasOwnProperty('commit')) { if (!entry.hasOwnProperty('commit')) {
body.name = branchFilter.val(); body.name = branchFilter.val();
body.create = true; body.create = true;
if (options.remote) {
body.name = options.remote()+"/"+body.name; if (options.remotes) {
var m = /^([^/]+)\/[^/.~*?\[]/.exec(body.name);
if (!m || remotes.indexOf(m[1]) === -1) {
body.name = remotes[0]+"/"+body.name;
}
} }
} else { } else {
if ($(this).hasClass('selected')) { if ($(this).hasClass('selected')) {
@ -2154,11 +2172,17 @@ RED.projects = (function() {
}, },
filter: function(data) { filter: function(data) {
var isCreateEntry = (!data.hasOwnProperty('commit')); var isCreateEntry = (!data.hasOwnProperty('commit'));
var filterTerm = branchFilterTerm;
if (remotes.length > 0) {
var m = /^([^/]+)\/[^/.~*?\[]/.exec(filterTerm);
if (filterTerm !== "" && (!m || remotes.indexOf(m[1]) == -1)) {
filterTerm = remotes[0]+"/"+filterTerm;
}
}
return ( return (
isCreateEntry && isCreateEntry &&
( (
branchFilterTerm !== "" && filterTerm !== "" && !branchNames.has(filterTerm)
branches.indexOf(branchPrefix+branchFilterTerm) === -1
) )
) || ) ||
( (
@ -2173,12 +2197,14 @@ RED.projects = (function() {
branchList.editableList('empty'); branchList.editableList('empty');
var start = Date.now(); var start = Date.now();
var spinner = addSpinnerOverlay(container).addClass("red-ui-component-spinner-contain"); var spinner = addSpinnerOverlay(container).addClass("red-ui-component-spinner-contain");
if (options.remote) { if (options.remotes) {
branchPrefix = options.remote()+"/"; remotes = options.remotes();
branchPrefix = remotes[0]+"/";
} else { } else {
branchPrefix = ""; branchPrefix = "";
remotes = [];
} }
branchNames = new Set();
sendRequest({ sendRequest({
url: url, url: url,
type: "GET", type: "GET",
@ -2190,6 +2216,7 @@ RED.projects = (function() {
branches = result.branches; branches = result.branches;
result.branches.forEach(function(b) { result.branches.forEach(function(b) {
branchList.editableList('addItem',b); branchList.editableList('addItem',b);
branchNames.add(b.name);
}); });
branchList.editableList('addItem',{}); branchList.editableList('addItem',{});
setTimeout(function() { setTimeout(function() {

View File

@ -830,10 +830,9 @@ RED.sidebar.versionControl = (function() {
var remoteBranchList = utils.createBranchList({ var remoteBranchList = utils.createBranchList({
placeholder: RED._("sidebar.project.versionControl.createRemoteBranchPlaceholder"), placeholder: RED._("sidebar.project.versionControl.createRemoteBranchPlaceholder"),
currentLabel: RED._("sidebar.project.versionControl.upstream"), currentLabel: RED._("sidebar.project.versionControl.upstream"),
remote: function() { remotes: function() {
var project = RED.projects.getActiveProject(); var project = RED.projects.getActiveProject();
var remotes = Object.keys(project.git.remotes); return Object.keys(project.git.remotes);
return remotes[0];
}, },
container: remoteBranchSubRow, container: remoteBranchSubRow,
onselect: function(body) { onselect: function(body) {