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

Fix up merge conflict handling

This commit is contained in:
Nick O'Leary 2018-02-08 22:22:58 +00:00
parent 2f6ac42efe
commit d5619d2b9d
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
5 changed files with 68 additions and 45 deletions

View File

@ -1768,7 +1768,7 @@ RED.diff = (function() {
// } // }
var actualLineNumber = hunk.diffStart + lineNumber; var actualLineNumber = hunk.diffStart + lineNumber;
var isMergeHeader = isConflict && /^..(<<<<<<<|=======$|>>>>>>>)/.test(lineText); var isMergeHeader = isConflict && /^\+\+(<<<<<<<|=======$|>>>>>>>)/.test(lineText);
var diffRow = $('<tr>').appendTo(codeBody); var diffRow = $('<tr>').appendTo(codeBody);
var localLineNo = $('<td class="lineno">').appendTo(diffRow); var localLineNo = $('<td class="lineno">').appendTo(diffRow);
var remoteLineNo; var remoteLineNo;
@ -1827,7 +1827,7 @@ RED.diff = (function() {
$('<span>').text(lineText.substring(prefixEnd)).appendTo(line); $('<span>').text(lineText.substring(prefixEnd)).appendTo(line);
} else { } else {
diffRow.addClass("mergeHeader"); diffRow.addClass("mergeHeader");
var isSeparator = /^..(=======$)/.test(lineText); var isSeparator = /^\+\+=======$/.test(lineText);
if (!isSeparator) { if (!isSeparator) {
var isOurs = /^..<<<<<<</.test(lineText); var isOurs = /^..<<<<<<</.test(lineText);
if (isOurs) { if (isOurs) {
@ -2047,7 +2047,7 @@ RED.diff = (function() {
} else { } else {
lines = diff.split("\n"); lines = diff.split("\n");
} }
var diffHeader = /^diff --git a\/(.*) b\/(.*)$/; var diffHeader = /^diff (?:(?:--git a\/(.*) b\/(.*))|(?:--cc (.*)))$/;
var fileHeader = /^\+\+\+ b\/(.*)\t?/; var fileHeader = /^\+\+\+ b\/(.*)\t?/;
var binaryFile = /^Binary files /; var binaryFile = /^Binary files /;
var hunkHeader = /^@@ -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @@ ?(.*)$/; var hunkHeader = /^@@ -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @@ ?(.*)$/;
@ -2066,7 +2066,7 @@ RED.diff = (function() {
} }
currentHunk = null; currentHunk = null;
currentFile = { currentFile = {
file: diffLine[1], file: diffLine[1]||diffLine[3],
hunks: [] hunks: []
} }
} else if (binaryFile.test(line)) { } else if (binaryFile.test(line)) {

View File

@ -51,10 +51,6 @@ RED.sidebar.versionControl = (function() {
// done(error,null); // done(error,null);
}, },
200: function(data) { 200: function(data) {
if (mergeConflictNotification) {
mergeConflictNotification.close();
mergeConflictNotification = null;
}
var title; var title;
if (state === 'unstaged') { if (state === 'unstaged') {
title = 'Unstaged changes : '+entry.file title = 'Unstaged changes : '+entry.file
@ -102,9 +98,7 @@ RED.sidebar.versionControl = (function() {
},{resolutions:resolution.resolutions[entry.file]}); },{resolutions:resolution.resolutions[entry.file]});
} }
} }
options.oncancel = showMergeConflictNotification;
RED.diff.showUnifiedDiff(options); RED.diff.showUnifiedDiff(options);
// console.log(data.diff);
}, },
400: { 400: {
'unexpected_error': function(error) { 'unexpected_error': function(error) {
@ -377,6 +371,16 @@ RED.sidebar.versionControl = (function() {
scrollOnAdd: false, scrollOnAdd: false,
addItem: function(row,index,entry) { addItem: function(row,index,entry) {
createChangeEntry(row,entry,entry.treeStatus,'unmerged'); createChangeEntry(row,entry,entry.treeStatus,'unmerged');
if (entry === emptyMergedItem) {
var toolbar = $('<div style="text-align: center"></div>').appendTo(row);
$('<button class="editor-button editor-button-small">commit</button>')
.appendTo(toolbar)
.click(function(evt) {
evt.preventDefault();
evt.stopPropagation();
showCommitBox();
});
}
}, },
sort: function(A,B) { sort: function(A,B) {
if (A.treeStatus === '?' && B.treeStatus !== '?') { if (A.treeStatus === '?' && B.treeStatus !== '?') {
@ -395,11 +399,7 @@ RED.sidebar.versionControl = (function() {
header = $('<div class="sidebar-version-control-change-header">Changes to commit</div>').appendTo(stagedContent); header = $('<div class="sidebar-version-control-change-header">Changes to commit</div>').appendTo(stagedContent);
bg = $('<div style="float: right"></div>').appendTo(header); bg = $('<div style="float: right"></div>').appendTo(header);
commitButton = $('<button class="editor-button editor-button-small" style="margin-right: 5px;">commit</button>') var showCommitBox = function() {
.appendTo(bg)
.click(function(evt) {
evt.preventDefault();
evt.stopPropagation();
commitMessage.val(""); commitMessage.val("");
submitCommitButton.attr("disabled",true); submitCommitButton.attr("disabled",true);
unstagedContent.css("height","30px"); unstagedContent.css("height","30px");
@ -416,7 +416,15 @@ RED.sidebar.versionControl = (function() {
stageAllButton.attr("disabled",true); stageAllButton.attr("disabled",true);
unstageAllButton.attr("disabled",true); unstageAllButton.attr("disabled",true);
commitButton.attr("disabled",true); commitButton.attr("disabled",true);
abortMergeButton.attr("disabled",true);
commitMessage.focus(); commitMessage.focus();
}
commitButton = $('<button class="editor-button editor-button-small" style="margin-right: 5px;">commit</button>')
.appendTo(bg)
.click(function(evt) {
evt.preventDefault();
evt.stopPropagation();
showCommitBox();
}); });
unstageAllButton = $('<button class="editor-button editor-button-small"><i class="fa fa-minus"></i> all</button>') unstageAllButton = $('<button class="editor-button editor-button-small"><i class="fa fa-minus"></i> all</button>')
.appendTo(bg) .appendTo(bg)
@ -467,6 +475,8 @@ RED.sidebar.versionControl = (function() {
stageAllButton.attr("disabled",false); stageAllButton.attr("disabled",false);
unstageAllButton.attr("disabled",false); unstageAllButton.attr("disabled",false);
commitButton.attr("disabled",false); commitButton.attr("disabled",false);
abortMergeButton.attr("disabled",false);
}) })
var submitCommitButton = $('<button class="editor-button">Commit</button>') var submitCommitButton = $('<button class="editor-button">Commit</button>')
.appendTo(commitToolbar) .appendTo(commitToolbar)
@ -1045,16 +1055,6 @@ RED.sidebar.versionControl = (function() {
// } // }
// } // }
function showMergeConflictNotification() {
if (isMerging) {
mergeConflictNotification = RED.notify("NLS: Automatic merging of remote changes failed. Fix the unmerged conflicts then commit the results."+
'<p><a href="#" onclick="RED.sidebar.versionControl.showLocalChanges(); return false;">'+'Show merge conflicts'+'</a></p>',"error",true);
}
}
function refreshFiles(result) { function refreshFiles(result) {
var files = result.files; var files = result.files;
if (bulkChangeSpinner) { if (bulkChangeSpinner) {
@ -1064,7 +1064,22 @@ RED.sidebar.versionControl = (function() {
isMerging = !!result.merging; isMerging = !!result.merging;
if (isMerging) { if (isMerging) {
if (!mergeConflictNotification) { if (!mergeConflictNotification) {
showMergeConflictNotification(); var text = "<p>Automatic merging of changes failed.</p><p>Fix the unmerged conflicts then commit the results.</p>";
var options = {
type: 'error',
fixed: true,
id: 'merge-conflict',
buttons: [
{
text: "Show merge conflicts",
click: function() {
mergeConflictNotification.hideNotification();
RED.sidebar.versionControl.showLocalChanges();
}
}
]
}
mergeConflictNotification = RED.notify(text,options);
} }
sidebarContent.addClass("sidebar-version-control-merging"); sidebarContent.addClass("sidebar-version-control-merging");
unmergedContent.show(); unmergedContent.show();

View File

@ -501,10 +501,10 @@
top: 4px; top: 4px;
right: 4px; right: 4px;
display: none; display: none;
}
button { button {
width: 24px; width: 24px;
} }
}
&:hover { &:hover {
.sidebar-version-control-change-entry-tools { .sidebar-version-control-change-entry-tools {

View File

@ -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)); return gitTools.pull(self.path, null, null, 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)); return gitTools.pull(this.path, remote.remote, remote.branch, authCache.get(this.name,this.remotes[remote.remote||self.currentRemote].fetch,username),getGitUser(user));
} }
}; };

View File

@ -428,12 +428,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,remote,branch,auth) { pull: function(cwd,remote,branch,auth,gitUser) {
var args = ["pull"]; var args = ["pull"];
if (remote && branch) { if (remote && branch) {
args.push(remote); args.push(remote);
args.push(branch); args.push(branch);
} }
if (gitUser && gitUser['name'] && gitUser['email']) {
args.unshift('user.name="'+gitUser['name']+'"');
args.unshift('-c');
args.unshift('user.email="'+gitUser['email']+'"');
args.unshift('-c');
}
//TODO: only do this if asked for
args.push("--allow-unrelated-histories");
var promise; var promise;
if (auth) { if (auth) {
if ( auth.key_path ) { if ( auth.key_path ) {
@ -556,7 +564,7 @@ module.exports = {
return runGitCommand(args,cwd,env); return runGitCommand(args,cwd,env);
}, },
getFileDiff(cwd,file,type) { getFileDiff(cwd,file,type) {
var args = ["diff"]; var args = ["diff","-w"];
if (type === "tree") { if (type === "tree") {
// nothing else to do // nothing else to do
} else if (type === "index") { } else if (type === "index") {