mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Handle allow-unrelated-histories option on pull
This commit is contained in:
parent
d5619d2b9d
commit
06a6a4408f
@ -870,20 +870,26 @@ RED.sidebar.versionControl = (function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('<button id="sidebar-version-control-repo-pull" class="sidebar-version-control-repo-sub-action editor-button"><i class="fa fa-long-arrow-down"></i> <span>pull</span></button>')
|
var pullRemote = function(options) {
|
||||||
.appendTo(row)
|
options = options || {};
|
||||||
.click(function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
var spinner = utils.addSpinnerOverlay(remoteBox).addClass("projects-dialog-spinner-contain");
|
var spinner = utils.addSpinnerOverlay(remoteBox).addClass("projects-dialog-spinner-contain");
|
||||||
var activeProject = RED.projects.getActiveProject();
|
var activeProject = RED.projects.getActiveProject();
|
||||||
var url = "projects/"+activeProject.name+"/pull";
|
var url = "projects/"+activeProject.name+"/pull";
|
||||||
if (activeProject.git.branches.remoteAlt) {
|
if (activeProject.git.branches.remoteAlt) {
|
||||||
url+="/"+activeProject.git.branches.remoteAlt;
|
url+="/"+activeProject.git.branches.remoteAlt;
|
||||||
}
|
}
|
||||||
if ($("#sidebar-version-control-repo-toolbar-set-upstream").prop('checked')) {
|
if (options.setUpstream || options.allowUnrelatedHistories) {
|
||||||
url+="?u=true"
|
url+="?";
|
||||||
|
}
|
||||||
|
if (options.setUpstream) {
|
||||||
|
url += "setUpstream=true"
|
||||||
|
if (options.allowUnrelatedHistories) {
|
||||||
|
url += "&";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (options.allowUnrelatedHistories) {
|
||||||
|
url += "allowUnrelatedHistories=true"
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.sendRequest({
|
utils.sendRequest({
|
||||||
url: url,
|
url: url,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
@ -898,7 +904,7 @@ RED.sidebar.versionControl = (function() {
|
|||||||
},
|
},
|
||||||
400: {
|
400: {
|
||||||
'git_local_overwrite': function(err) {
|
'git_local_overwrite': function(err) {
|
||||||
RED.notify("Unable to pull remote changes; your unstaged local changes would be overwritten. Commit your changes and try again."+
|
RED.notify("<p>Unable to pull remote changes; your unstaged local changes would be overwritten.</p><p>Commit your changes and try again.</p>"+
|
||||||
'<p><a href="#" onclick="RED.sidebar.versionControl.showLocalChanges(); return false;">'+'Show unstaged changes'+'</a></p>',"error",false,10000000);
|
'<p><a href="#" onclick="RED.sidebar.versionControl.showLocalChanges(); return false;">'+'Show unstaged changes'+'</a></p>',"error",false,10000000);
|
||||||
},
|
},
|
||||||
'git_pull_merge_conflict': function(err) {
|
'git_pull_merge_conflict': function(err) {
|
||||||
@ -907,18 +913,44 @@ RED.sidebar.versionControl = (function() {
|
|||||||
'git_connection_failed': function(err) {
|
'git_connection_failed': function(err) {
|
||||||
RED.notify("Could not connect to remote repository: "+err.toString(),"warning")
|
RED.notify("Could not connect to remote repository: "+err.toString(),"warning")
|
||||||
},
|
},
|
||||||
'unexpected_error': function(error) {
|
|
||||||
console.log(error);
|
|
||||||
// done(error,null);
|
|
||||||
},
|
|
||||||
'git_pull_unrelated_history': function(error) {
|
'git_pull_unrelated_history': function(error) {
|
||||||
RED.notify("Unable to pull remote changes; refusing to merge unrelated histories.","error");
|
var notification = RED.notify("<p>The remote has an unrelated history of commits.</p><p>Are you sure you want to pull the changes into your local repository?</p>",{
|
||||||
|
type: 'error',
|
||||||
|
modal: true,
|
||||||
|
fixed: true,
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
text: RED._("common.label.cancel"),
|
||||||
|
click: function() {
|
||||||
|
notification.close();
|
||||||
|
}
|
||||||
|
},{
|
||||||
|
text: 'Pull changes',
|
||||||
|
click: function() {
|
||||||
|
notification.close();
|
||||||
|
options.allowUnrelatedHistories = true;
|
||||||
|
pullRemote(options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
},
|
||||||
|
'*': function(error) {
|
||||||
|
utils.reportUnexpectedError(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},{}).always(function() {
|
},{}).always(function() {
|
||||||
spinner.remove();
|
spinner.remove();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
$('<button id="sidebar-version-control-repo-pull" class="sidebar-version-control-repo-sub-action editor-button"><i class="fa fa-long-arrow-down"></i> <span>pull</span></button>')
|
||||||
|
.appendTo(row)
|
||||||
|
.click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
pullRemote({
|
||||||
|
setUpstream: $("#sidebar-version-control-repo-toolbar-set-upstream").prop('checked')
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('<div class="component-shade sidebar-version-control-shade">').appendTo(sidebarContent);
|
$('<div class="component-shade sidebar-version-control-shade">').appendTo(sidebarContent);
|
||||||
|
@ -353,8 +353,9 @@ module.exports = {
|
|||||||
app.post("/:id/pull/?*", needsPermission("projects.write"), function(req,res) {
|
app.post("/:id/pull/?*", needsPermission("projects.write"), function(req,res) {
|
||||||
var projectName = req.params.id;
|
var projectName = req.params.id;
|
||||||
var remoteBranchName = req.params[0];
|
var remoteBranchName = req.params[0];
|
||||||
var setRemote = req.query.u;
|
var setUpstream = req.query.setUpstream;
|
||||||
runtime.storage.projects.pull(req.user, projectName,remoteBranchName,setRemote).then(function(data) {
|
var allowUnrelatedHistories = req.query.allowUnrelatedHistories;
|
||||||
|
runtime.storage.projects.pull(req.user, projectName,remoteBranchName,setUpstream,allowUnrelatedHistories).then(function(data) {
|
||||||
res.status(204).end();
|
res.status(204).end();
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
|
@ -512,7 +512,7 @@ Project.prototype.push = function (user,remoteBranchName,setRemote) {
|
|||||||
return gitTools.push(this.path, remote.remote || this.currentRemote,remote.branch, setRemote, authCache.get(this.name,this.remotes[remote.remote || this.currentRemote].fetch,username));
|
return gitTools.push(this.path, remote.remote || this.currentRemote,remote.branch, setRemote, authCache.get(this.name,this.remotes[remote.remote || this.currentRemote].fetch,username));
|
||||||
};
|
};
|
||||||
|
|
||||||
Project.prototype.pull = function (user,remoteBranchName,setRemote) {
|
Project.prototype.pull = function (user,remoteBranchName,setRemote,allowUnrelatedHistories) {
|
||||||
var username;
|
var username;
|
||||||
if (!user) {
|
if (!user) {
|
||||||
username = "_";
|
username = "_";
|
||||||
@ -523,11 +523,11 @@ Project.prototype.pull = function (user,remoteBranchName,setRemote) {
|
|||||||
if (setRemote) {
|
if (setRemote) {
|
||||||
return gitTools.setUpstream(this.path, remoteBranchName).then(function() {
|
return gitTools.setUpstream(this.path, remoteBranchName).then(function() {
|
||||||
self.currentRemote = self.parseRemoteBranch(remoteBranchName).remote;
|
self.currentRemote = self.parseRemoteBranch(remoteBranchName).remote;
|
||||||
return gitTools.pull(self.path, null, null, authCache.get(self.name,self.remotes[self.currentRemote].fetch,username),getGitUser(user));
|
return gitTools.pull(self.path, null, null, allowUnrelatedHistories, authCache.get(self.name,self.remotes[self.currentRemote].fetch,username),getGitUser(user));
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
var remote = this.parseRemoteBranch(remoteBranchName);
|
var remote = this.parseRemoteBranch(remoteBranchName);
|
||||||
return gitTools.pull(this.path, remote.remote, remote.branch, authCache.get(this.name,this.remotes[remote.remote||self.currentRemote].fetch,username),getGitUser(user));
|
return gitTools.pull(this.path, remote.remote, remote.branch, allowUnrelatedHistories, authCache.get(this.name,this.remotes[remote.remote||self.currentRemote].fetch,username),getGitUser(user));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -428,7 +428,7 @@ module.exports = {
|
|||||||
var args = ["branch","--set-upstream-to",remoteBranch];
|
var args = ["branch","--set-upstream-to",remoteBranch];
|
||||||
return runGitCommand(args,cwd);
|
return runGitCommand(args,cwd);
|
||||||
},
|
},
|
||||||
pull: function(cwd,remote,branch,auth,gitUser) {
|
pull: function(cwd,remote,branch,allowUnrelatedHistories,auth,gitUser) {
|
||||||
var args = ["pull"];
|
var args = ["pull"];
|
||||||
if (remote && branch) {
|
if (remote && branch) {
|
||||||
args.push(remote);
|
args.push(remote);
|
||||||
@ -440,8 +440,9 @@ module.exports = {
|
|||||||
args.unshift('user.email="'+gitUser['email']+'"');
|
args.unshift('user.email="'+gitUser['email']+'"');
|
||||||
args.unshift('-c');
|
args.unshift('-c');
|
||||||
}
|
}
|
||||||
//TODO: only do this if asked for
|
if (allowUnrelatedHistories) {
|
||||||
args.push("--allow-unrelated-histories");
|
args.push("--allow-unrelated-histories");
|
||||||
|
}
|
||||||
var promise;
|
var promise;
|
||||||
if (auth) {
|
if (auth) {
|
||||||
if ( auth.key_path ) {
|
if ( auth.key_path ) {
|
||||||
|
@ -241,9 +241,9 @@ function push(user, project,remoteBranchName,setRemote) {
|
|||||||
checkActiveProject(project);
|
checkActiveProject(project);
|
||||||
return activeProject.push(user,remoteBranchName,setRemote);
|
return activeProject.push(user,remoteBranchName,setRemote);
|
||||||
}
|
}
|
||||||
function pull(user, project,remoteBranchName,setRemote) {
|
function pull(user, project,remoteBranchName,setRemote,allowUnrelatedHistories) {
|
||||||
checkActiveProject(project);
|
checkActiveProject(project);
|
||||||
return activeProject.pull(user,remoteBranchName,setRemote).then(function() {
|
return activeProject.pull(user,remoteBranchName,setRemote,allowUnrelatedHistories).then(function() {
|
||||||
return reloadActiveProject("pull");
|
return reloadActiveProject("pull");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user