diff --git a/editor/js/ui/projects/tab-versionControl.js b/editor/js/ui/projects/tab-versionControl.js index 03f06607d..798c26092 100644 --- a/editor/js/ui/projects/tab-versionControl.js +++ b/editor/js/ui/projects/tab-versionControl.js @@ -870,54 +870,86 @@ RED.sidebar.versionControl = (function() { }); }); + var pullRemote = function(options) { + options = options || {}; + var spinner = utils.addSpinnerOverlay(remoteBox).addClass("projects-dialog-spinner-contain"); + var activeProject = RED.projects.getActiveProject(); + var url = "projects/"+activeProject.name+"/pull"; + if (activeProject.git.branches.remoteAlt) { + url+="/"+activeProject.git.branches.remoteAlt; + } + if (options.setUpstream || options.allowUnrelatedHistories) { + url+="?"; + } + if (options.setUpstream) { + url += "setUpstream=true" + if (options.allowUnrelatedHistories) { + url += "&"; + } + } + if (options.allowUnrelatedHistories) { + url += "allowUnrelatedHistories=true" + } + utils.sendRequest({ + url: url, + type: "POST", + responses: { + 0: function(error) { + console.log(error); + // done(error,null); + }, + 200: function(data) { + refresh(true); + closeRemoteBox(); + }, + 400: { + '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.

"+ + '

'+'Show unstaged changes'+'

',"error",false,10000000); + }, + 'git_pull_merge_conflict': function(err) { + refresh(true); + }, + 'git_connection_failed': function(err) { + RED.notify("Could not connect to remote repository: "+err.toString(),"warning") + }, + 'git_pull_unrelated_history': function(error) { + var notification = RED.notify("

The remote has an unrelated history of commits.

Are you sure you want to pull the changes into your local repository?

",{ + 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() { + spinner.remove(); + }); + } $('') .appendTo(row) .click(function(e) { e.preventDefault(); - var spinner = utils.addSpinnerOverlay(remoteBox).addClass("projects-dialog-spinner-contain"); - var activeProject = RED.projects.getActiveProject(); - var url = "projects/"+activeProject.name+"/pull"; - if (activeProject.git.branches.remoteAlt) { - url+="/"+activeProject.git.branches.remoteAlt; - } - if ($("#sidebar-version-control-repo-toolbar-set-upstream").prop('checked')) { - url+="?u=true" - } - - utils.sendRequest({ - url: url, - type: "POST", - responses: { - 0: function(error) { - console.log(error); - // done(error,null); - }, - 200: function(data) { - refresh(true); - closeRemoteBox(); - }, - 400: { - '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."+ - '

'+'Show unstaged changes'+'

',"error",false,10000000); - }, - 'git_pull_merge_conflict': function(err) { - refresh(true); - }, - 'git_connection_failed': function(err) { - 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) { - RED.notify("Unable to pull remote changes; refusing to merge unrelated histories.","error"); - } - }, - } - },{}).always(function() { - spinner.remove(); + pullRemote({ + setUpstream: $("#sidebar-version-control-repo-toolbar-set-upstream").prop('checked') }); }); diff --git a/red/api/editor/projects/index.js b/red/api/editor/projects/index.js index ef6823d38..440d6a8bb 100644 --- a/red/api/editor/projects/index.js +++ b/red/api/editor/projects/index.js @@ -353,8 +353,9 @@ module.exports = { app.post("/:id/pull/?*", needsPermission("projects.write"), function(req,res) { var projectName = req.params.id; var remoteBranchName = req.params[0]; - var setRemote = req.query.u; - runtime.storage.projects.pull(req.user, projectName,remoteBranchName,setRemote).then(function(data) { + var setUpstream = req.query.setUpstream; + var allowUnrelatedHistories = req.query.allowUnrelatedHistories; + runtime.storage.projects.pull(req.user, projectName,remoteBranchName,setUpstream,allowUnrelatedHistories).then(function(data) { res.status(204).end(); }) .catch(function(err) { diff --git a/red/runtime/storage/localfilesystem/projects/Project.js b/red/runtime/storage/localfilesystem/projects/Project.js index aaa900448..7f03aa109 100644 --- a/red/runtime/storage/localfilesystem/projects/Project.js +++ b/red/runtime/storage/localfilesystem/projects/Project.js @@ -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)); }; -Project.prototype.pull = function (user,remoteBranchName,setRemote) { +Project.prototype.pull = function (user,remoteBranchName,setRemote,allowUnrelatedHistories) { var username; if (!user) { username = "_"; @@ -523,11 +523,11 @@ Project.prototype.pull = function (user,remoteBranchName,setRemote) { if (setRemote) { return gitTools.setUpstream(this.path, remoteBranchName).then(function() { 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 { 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)); } }; diff --git a/red/runtime/storage/localfilesystem/projects/git/index.js b/red/runtime/storage/localfilesystem/projects/git/index.js index ecb4e3d72..dfa6a03f7 100644 --- a/red/runtime/storage/localfilesystem/projects/git/index.js +++ b/red/runtime/storage/localfilesystem/projects/git/index.js @@ -428,7 +428,7 @@ module.exports = { var args = ["branch","--set-upstream-to",remoteBranch]; return runGitCommand(args,cwd); }, - pull: function(cwd,remote,branch,auth,gitUser) { + pull: function(cwd,remote,branch,allowUnrelatedHistories,auth,gitUser) { var args = ["pull"]; if (remote && branch) { args.push(remote); @@ -440,8 +440,9 @@ module.exports = { args.unshift('user.email="'+gitUser['email']+'"'); args.unshift('-c'); } - //TODO: only do this if asked for - args.push("--allow-unrelated-histories"); + if (allowUnrelatedHistories) { + args.push("--allow-unrelated-histories"); + } var promise; if (auth) { if ( auth.key_path ) { diff --git a/red/runtime/storage/localfilesystem/projects/index.js b/red/runtime/storage/localfilesystem/projects/index.js index b30dd18d5..88e85c05a 100644 --- a/red/runtime/storage/localfilesystem/projects/index.js +++ b/red/runtime/storage/localfilesystem/projects/index.js @@ -241,9 +241,9 @@ function push(user, project,remoteBranchName,setRemote) { checkActiveProject(project); return activeProject.push(user,remoteBranchName,setRemote); } -function pull(user, project,remoteBranchName,setRemote) { +function pull(user, project,remoteBranchName,setRemote,allowUnrelatedHistories) { checkActiveProject(project); - return activeProject.pull(user,remoteBranchName,setRemote).then(function() { + return activeProject.pull(user,remoteBranchName,setRemote,allowUnrelatedHistories).then(function() { return reloadActiveProject("pull"); }); }