From e5ff25b92da5886ae0b5ecab5e8ee45737b99f98 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 23 Nov 2017 20:52:15 +0000 Subject: [PATCH] Fix project pull with authentication --- red/api/editor/projects/index.js | 2 +- .../storage/localfilesystem/projects/Project.js | 3 ++- .../storage/localfilesystem/projects/git/index.js | 10 ++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/red/api/editor/projects/index.js b/red/api/editor/projects/index.js index 5b0c06709..78002146a 100644 --- a/red/api/editor/projects/index.js +++ b/red/api/editor/projects/index.js @@ -297,7 +297,7 @@ module.exports = { }); // Pull remote commits - app.get("/:id/pull/?*", function(req,res) { + app.post("/:id/pull/?*", function(req,res) { var projectName = req.params.id; var remoteBranchName = req.params[0]; var setRemote = req.query.u; diff --git a/red/runtime/storage/localfilesystem/projects/Project.js b/red/runtime/storage/localfilesystem/projects/Project.js index b67db60f7..dbdfb975f 100644 --- a/red/runtime/storage/localfilesystem/projects/Project.js +++ b/red/runtime/storage/localfilesystem/projects/Project.js @@ -296,9 +296,10 @@ Project.prototype.push = function (remoteBranchName,setRemote) { }; Project.prototype.pull = function (remoteBranchName,setRemote) { + var self = this; if (setRemote) { 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 { return gitTools.pull(this.path, remoteBranchName, getAuth(this.name,'origin')); diff --git a/red/runtime/storage/localfilesystem/projects/git/index.js b/red/runtime/storage/localfilesystem/projects/git/index.js index c695fa4c0..58b1a4a17 100644 --- a/red/runtime/storage/localfilesystem/projects/git/index.js +++ b/red/runtime/storage/localfilesystem/projects/git/index.js @@ -322,14 +322,20 @@ module.exports = { var args = ["branch","--set-upstream-to",remoteBranch]; return runGitCommand(args,cwd); }, - pull: function(cwd,remoteBranch) { + pull: function(cwd,remoteBranch,auth) { var args = ["pull"]; var m = /^(.*?)\/(.*)$/.exec(remoteBranch); if (m) { args.push(m[1]); 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)) { var e = new Error("NLS: pull failed - merge conflict"); e.code = "git_pull_merge_conflict";