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

Fix project pull with authentication

This commit is contained in:
Nick O'Leary 2017-11-23 20:52:15 +00:00
parent 5c88888e02
commit e5ff25b92d
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 11 additions and 4 deletions

View File

@ -297,7 +297,7 @@ module.exports = {
}); });
// Pull remote commits // Pull remote commits
app.get("/:id/pull/?*", function(req,res) { app.post("/:id/pull/?*", 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 setRemote = req.query.u;

View File

@ -296,9 +296,10 @@ Project.prototype.push = function (remoteBranchName,setRemote) {
}; };
Project.prototype.pull = function (remoteBranchName,setRemote) { Project.prototype.pull = function (remoteBranchName,setRemote) {
var self = this;
if (setRemote) { if (setRemote) {
return gitTools.setUpstream(this.path, remoteBranchName).then(function() { return gitTools.setUpstream(this.path, remoteBranchName).then(function() {
return gitTools.pull(this.path, null, getAuth(this.name,'origin')); return gitTools.pull(self.path, null, getAuth(self.name,'origin'));
}) })
} else { } else {
return gitTools.pull(this.path, remoteBranchName, getAuth(this.name,'origin')); return gitTools.pull(this.path, remoteBranchName, getAuth(this.name,'origin'));

View File

@ -322,14 +322,20 @@ 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,remoteBranch) { pull: function(cwd,remoteBranch,auth) {
var args = ["pull"]; var args = ["pull"];
var m = /^(.*?)\/(.*)$/.exec(remoteBranch); var m = /^(.*?)\/(.*)$/.exec(remoteBranch);
if (m) { if (m) {
args.push(m[1]); args.push(m[1]);
args.push(m[2]) args.push(m[2])
} }
return runGitCommand(args,cwd).otherwise(function(err) { var promise;
if (auth) {
promise = runGitCommandWithAuth(args,cwd,auth);
} else {
promise = runGitCommand(args,cwd)
}
return promise.catch(function(err) {
if (/CONFLICT/.test(err.stdout)) { if (/CONFLICT/.test(err.stdout)) {
var e = new Error("NLS: pull failed - merge conflict"); var e = new Error("NLS: pull failed - merge conflict");
e.code = "git_pull_merge_conflict"; e.code = "git_pull_merge_conflict";