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:
parent
0de49e2a75
commit
4c24bd4ab9
@ -2100,6 +2100,8 @@ RED.projects = (function() {
|
||||
var branchFilterTerm = "";
|
||||
var branchFilterCreateItem;
|
||||
var branches = [];
|
||||
var branchNames = new Set();
|
||||
var remotes = [];
|
||||
var branchPrefix = "";
|
||||
var container = $('<div class="red-ui-projects-branch-list">').appendTo(options.container);
|
||||
|
||||
@ -2107,18 +2109,30 @@ RED.projects = (function() {
|
||||
delay: 200,
|
||||
change: function() {
|
||||
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")) {
|
||||
branchFilterCreateItem.addClass("input-error");
|
||||
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 {
|
||||
if (branchFilterCreateItem.hasClass("input-error")) {
|
||||
branchFilterCreateItem.removeClass("input-error");
|
||||
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");
|
||||
}
|
||||
@ -2151,8 +2165,12 @@ RED.projects = (function() {
|
||||
if (!entry.hasOwnProperty('commit')) {
|
||||
body.name = branchFilter.val();
|
||||
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 {
|
||||
if ($(this).hasClass('selected')) {
|
||||
@ -2167,11 +2185,17 @@ RED.projects = (function() {
|
||||
},
|
||||
filter: function(data) {
|
||||
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 (
|
||||
isCreateEntry &&
|
||||
(
|
||||
branchFilterTerm !== "" &&
|
||||
branches.indexOf(branchPrefix+branchFilterTerm) === -1
|
||||
filterTerm !== "" && !branchNames.has(filterTerm)
|
||||
)
|
||||
) ||
|
||||
(
|
||||
@ -2186,12 +2210,14 @@ RED.projects = (function() {
|
||||
branchList.editableList('empty');
|
||||
var start = Date.now();
|
||||
var spinner = addSpinnerOverlay(container).addClass("red-ui-component-spinner-contain");
|
||||
if (options.remote) {
|
||||
branchPrefix = options.remote()+"/";
|
||||
if (options.remotes) {
|
||||
remotes = options.remotes();
|
||||
branchPrefix = remotes[0]+"/";
|
||||
} else {
|
||||
branchPrefix = "";
|
||||
remotes = [];
|
||||
}
|
||||
|
||||
branchNames = new Set();
|
||||
sendRequest({
|
||||
url: url,
|
||||
type: "GET",
|
||||
@ -2203,6 +2229,7 @@ RED.projects = (function() {
|
||||
branches = result.branches;
|
||||
result.branches.forEach(function(b) {
|
||||
branchList.editableList('addItem',b);
|
||||
branchNames.add(b.name);
|
||||
});
|
||||
branchList.editableList('addItem',{});
|
||||
setTimeout(function() {
|
||||
|
@ -830,10 +830,9 @@ RED.sidebar.versionControl = (function() {
|
||||
var remoteBranchList = utils.createBranchList({
|
||||
placeholder: RED._("sidebar.project.versionControl.createRemoteBranchPlaceholder"),
|
||||
currentLabel: RED._("sidebar.project.versionControl.upstream"),
|
||||
remote: function() {
|
||||
remotes: function() {
|
||||
var project = RED.projects.getActiveProject();
|
||||
var remotes = Object.keys(project.git.remotes);
|
||||
return remotes[0];
|
||||
return Object.keys(project.git.remotes);
|
||||
},
|
||||
container: remoteBranchSubRow,
|
||||
onselect: function(body) {
|
||||
|
Loading…
Reference in New Issue
Block a user