Skip to content

Commit 06a6a44

Browse files
committed
Handle allow-unrelated-histories option on pull
1 parent d5619d2 commit 06a6a44

5 files changed

Lines changed: 87 additions & 53 deletions

File tree

editor/js/ui/projects/tab-versionControl.js

Lines changed: 75 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -870,54 +870,86 @@ RED.sidebar.versionControl = (function() {
870870
});
871871
});
872872

873-
$('<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>')
874-
.appendTo(row)
875-
.click(function(e) {
876-
e.preventDefault();
877-
var spinner = utils.addSpinnerOverlay(remoteBox).addClass("projects-dialog-spinner-contain");
878-
var activeProject = RED.projects.getActiveProject();
879-
var url = "projects/"+activeProject.name+"/pull";
880-
if (activeProject.git.branches.remoteAlt) {
881-
url+="/"+activeProject.git.branches.remoteAlt;
882-
}
883-
if ($("#sidebar-version-control-repo-toolbar-set-upstream").prop('checked')) {
884-
url+="?u=true"
873+
var pullRemote = function(options) {
874+
options = options || {};
875+
var spinner = utils.addSpinnerOverlay(remoteBox).addClass("projects-dialog-spinner-contain");
876+
var activeProject = RED.projects.getActiveProject();
877+
var url = "projects/"+activeProject.name+"/pull";
878+
if (activeProject.git.branches.remoteAlt) {
879+
url+="/"+activeProject.git.branches.remoteAlt;
880+
}
881+
if (options.setUpstream || options.allowUnrelatedHistories) {
882+
url+="?";
883+
}
884+
if (options.setUpstream) {
885+
url += "setUpstream=true"
886+
if (options.allowUnrelatedHistories) {
887+
url += "&";
885888
}
886-
887-
utils.sendRequest({
888-
url: url,
889-
type: "POST",
890-
responses: {
891-
0: function(error) {
892-
console.log(error);
893-
// done(error,null);
889+
}
890+
if (options.allowUnrelatedHistories) {
891+
url += "allowUnrelatedHistories=true"
892+
}
893+
utils.sendRequest({
894+
url: url,
895+
type: "POST",
896+
responses: {
897+
0: function(error) {
898+
console.log(error);
899+
// done(error,null);
900+
},
901+
200: function(data) {
902+
refresh(true);
903+
closeRemoteBox();
904+
},
905+
400: {
906+
'git_local_overwrite': function(err) {
907+
RED.notify("<p>Unable to pull remote changes; your unstaged local changes would be overwritten.</p><p>Commit your changes and try again.</p>"+
908+
'<p><a href="#" onclick="RED.sidebar.versionControl.showLocalChanges(); return false;">'+'Show unstaged changes'+'</a></p>',"error",false,10000000);
894909
},
895-
200: function(data) {
910+
'git_pull_merge_conflict': function(err) {
896911
refresh(true);
897-
closeRemoteBox();
898912
},
899-
400: {
900-
'git_local_overwrite': function(err) {
901-
RED.notify("Unable to pull remote changes; your unstaged local changes would be overwritten. Commit your changes and try again."+
902-
'<p><a href="#" onclick="RED.sidebar.versionControl.showLocalChanges(); return false;">'+'Show unstaged changes'+'</a></p>',"error",false,10000000);
903-
},
904-
'git_pull_merge_conflict': function(err) {
905-
refresh(true);
906-
},
907-
'git_connection_failed': function(err) {
908-
RED.notify("Could not connect to remote repository: "+err.toString(),"warning")
909-
},
910-
'unexpected_error': function(error) {
911-
console.log(error);
912-
// done(error,null);
913-
},
914-
'git_pull_unrelated_history': function(error) {
915-
RED.notify("Unable to pull remote changes; refusing to merge unrelated histories.","error");
916-
}
913+
'git_connection_failed': function(err) {
914+
RED.notify("Could not connect to remote repository: "+err.toString(),"warning")
917915
},
918-
}
919-
},{}).always(function() {
920-
spinner.remove();
916+
'git_pull_unrelated_history': function(error) {
917+
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>",{
918+
type: 'error',
919+
modal: true,
920+
fixed: true,
921+
buttons: [
922+
{
923+
text: RED._("common.label.cancel"),
924+
click: function() {
925+
notification.close();
926+
}
927+
},{
928+
text: 'Pull changes',
929+
click: function() {
930+
notification.close();
931+
options.allowUnrelatedHistories = true;
932+
pullRemote(options)
933+
}
934+
}
935+
]
936+
});
937+
},
938+
'*': function(error) {
939+
utils.reportUnexpectedError(error);
940+
}
941+
},
942+
}
943+
},{}).always(function() {
944+
spinner.remove();
945+
});
946+
}
947+
$('<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>')
948+
.appendTo(row)
949+
.click(function(e) {
950+
e.preventDefault();
951+
pullRemote({
952+
setUpstream: $("#sidebar-version-control-repo-toolbar-set-upstream").prop('checked')
921953
});
922954
});
923955

red/api/editor/projects/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,9 @@ module.exports = {
353353
app.post("/:id/pull/?*", needsPermission("projects.write"), function(req,res) {
354354
var projectName = req.params.id;
355355
var remoteBranchName = req.params[0];
356-
var setRemote = req.query.u;
357-
runtime.storage.projects.pull(req.user, projectName,remoteBranchName,setRemote).then(function(data) {
356+
var setUpstream = req.query.setUpstream;
357+
var allowUnrelatedHistories = req.query.allowUnrelatedHistories;
358+
runtime.storage.projects.pull(req.user, projectName,remoteBranchName,setUpstream,allowUnrelatedHistories).then(function(data) {
358359
res.status(204).end();
359360
})
360361
.catch(function(err) {

red/runtime/storage/localfilesystem/projects/Project.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ Project.prototype.push = function (user,remoteBranchName,setRemote) {
512512
return gitTools.push(this.path, remote.remote || this.currentRemote,remote.branch, setRemote, authCache.get(this.name,this.remotes[remote.remote || this.currentRemote].fetch,username));
513513
};
514514

515-
Project.prototype.pull = function (user,remoteBranchName,setRemote) {
515+
Project.prototype.pull = function (user,remoteBranchName,setRemote,allowUnrelatedHistories) {
516516
var username;
517517
if (!user) {
518518
username = "_";
@@ -523,11 +523,11 @@ Project.prototype.pull = function (user,remoteBranchName,setRemote) {
523523
if (setRemote) {
524524
return gitTools.setUpstream(this.path, remoteBranchName).then(function() {
525525
self.currentRemote = self.parseRemoteBranch(remoteBranchName).remote;
526-
return gitTools.pull(self.path, null, null, authCache.get(self.name,self.remotes[self.currentRemote].fetch,username),getGitUser(user));
526+
return gitTools.pull(self.path, null, null, allowUnrelatedHistories, authCache.get(self.name,self.remotes[self.currentRemote].fetch,username),getGitUser(user));
527527
})
528528
} else {
529529
var remote = this.parseRemoteBranch(remoteBranchName);
530-
return gitTools.pull(this.path, remote.remote, remote.branch, authCache.get(this.name,this.remotes[remote.remote||self.currentRemote].fetch,username),getGitUser(user));
530+
return gitTools.pull(this.path, remote.remote, remote.branch, allowUnrelatedHistories, authCache.get(this.name,this.remotes[remote.remote||self.currentRemote].fetch,username),getGitUser(user));
531531
}
532532
};
533533

red/runtime/storage/localfilesystem/projects/git/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ module.exports = {
428428
var args = ["branch","--set-upstream-to",remoteBranch];
429429
return runGitCommand(args,cwd);
430430
},
431-
pull: function(cwd,remote,branch,auth,gitUser) {
431+
pull: function(cwd,remote,branch,allowUnrelatedHistories,auth,gitUser) {
432432
var args = ["pull"];
433433
if (remote && branch) {
434434
args.push(remote);
@@ -440,8 +440,9 @@ module.exports = {
440440
args.unshift('user.email="'+gitUser['email']+'"');
441441
args.unshift('-c');
442442
}
443-
//TODO: only do this if asked for
444-
args.push("--allow-unrelated-histories");
443+
if (allowUnrelatedHistories) {
444+
args.push("--allow-unrelated-histories");
445+
}
445446
var promise;
446447
if (auth) {
447448
if ( auth.key_path ) {

red/runtime/storage/localfilesystem/projects/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ function push(user, project,remoteBranchName,setRemote) {
241241
checkActiveProject(project);
242242
return activeProject.push(user,remoteBranchName,setRemote);
243243
}
244-
function pull(user, project,remoteBranchName,setRemote) {
244+
function pull(user, project,remoteBranchName,setRemote,allowUnrelatedHistories) {
245245
checkActiveProject(project);
246-
return activeProject.pull(user,remoteBranchName,setRemote).then(function() {
246+
return activeProject.pull(user,remoteBranchName,setRemote,allowUnrelatedHistories).then(function() {
247247
return reloadActiveProject("pull");
248248
});
249249
}

0 commit comments

Comments
 (0)