mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge branch "projects"
This commit is contained in:
@@ -1678,9 +1678,10 @@ RED.diff = (function() {
|
||||
|
||||
function createUnifiedDiffTable(files,commitOptions) {
|
||||
var diffPanel = $('<div></div>');
|
||||
console.log(files);
|
||||
files.forEach(function(file) {
|
||||
var hunks = file.hunks;
|
||||
|
||||
var isBinary = file.binary;
|
||||
var codeTable = $("<table>").appendTo(diffPanel);
|
||||
$('<colgroup><col width="50"><col width="50"><col width="100%"></colgroup>').appendTo(codeTable);
|
||||
var codeBody = $('<tbody>').appendTo(codeTable);
|
||||
@@ -1744,142 +1745,148 @@ RED.diff = (function() {
|
||||
})
|
||||
}
|
||||
|
||||
if (isBinary) {
|
||||
var diffBinaryRow = $('<tr class="node-text-diff-header">').appendTo(codeBody);
|
||||
var binaryContent = $('<td colspan="3"></td>').appendTo(diffBinaryRow);
|
||||
$('<span></span>').text("Cannot show binary file contents").appendTo(binaryContent);
|
||||
|
||||
hunks.forEach(function(hunk) {
|
||||
var diffRow = $('<tr class="node-text-diff-header">').appendTo(codeBody);
|
||||
var content = $('<td colspan="3"></td>').appendTo(diffRow);
|
||||
var label = $('<span></span>').text(hunk.header).appendTo(content);
|
||||
var isConflict = hunk.conflict;
|
||||
var localLine = hunk.localStartLine;
|
||||
var remoteLine = hunk.remoteStartLine;
|
||||
if (isConflict) {
|
||||
unresolvedConflicts++;
|
||||
}
|
||||
|
||||
hunk.lines.forEach(function(lineText,lineNumber) {
|
||||
// if (lineText[0] === '\\' || lineText === "") {
|
||||
// // Comment line - bail out of this hunk
|
||||
// break;
|
||||
// }
|
||||
|
||||
var actualLineNumber = hunk.diffStart + lineNumber;
|
||||
var isMergeHeader = isConflict && /^..(<<<<<<<|=======$|>>>>>>>)/.test(lineText);
|
||||
var diffRow = $('<tr>').appendTo(codeBody);
|
||||
var localLineNo = $('<td class="lineno">').appendTo(diffRow);
|
||||
var remoteLineNo;
|
||||
if (!isMergeHeader) {
|
||||
remoteLineNo = $('<td class="lineno">').appendTo(diffRow);
|
||||
} else {
|
||||
localLineNo.attr('colspan',2);
|
||||
}
|
||||
var line = $('<td class="linetext">').appendTo(diffRow);
|
||||
var prefixStart = 0;
|
||||
var prefixEnd = 1;
|
||||
} else {
|
||||
hunks.forEach(function(hunk) {
|
||||
var diffRow = $('<tr class="node-text-diff-header">').appendTo(codeBody);
|
||||
var content = $('<td colspan="3"></td>').appendTo(diffRow);
|
||||
var label = $('<span></span>').text(hunk.header).appendTo(content);
|
||||
var isConflict = hunk.conflict;
|
||||
var localLine = hunk.localStartLine;
|
||||
var remoteLine = hunk.remoteStartLine;
|
||||
if (isConflict) {
|
||||
prefixEnd = 2;
|
||||
unresolvedConflicts++;
|
||||
}
|
||||
if (!isMergeHeader) {
|
||||
var changeMarker = lineText[0];
|
||||
if (isConflict && !commitOptions.unmerged && changeMarker === ' ') {
|
||||
changeMarker = lineText[1];
|
||||
}
|
||||
$('<span class="prefix">').text(changeMarker).appendTo(line);
|
||||
var handledlLine = false;
|
||||
if (isConflict && commitOptions.unmerged) {
|
||||
$('<span class="prefix">').text(lineText[1]).appendTo(line);
|
||||
if (lineText[0] === '+') {
|
||||
localLineNo.text(localLine++);
|
||||
handledlLine = true;
|
||||
}
|
||||
if (lineText[1] === '+') {
|
||||
remoteLineNo.text(remoteLine++);
|
||||
handledlLine = true;
|
||||
}
|
||||
|
||||
hunk.lines.forEach(function(lineText,lineNumber) {
|
||||
// if (lineText[0] === '\\' || lineText === "") {
|
||||
// // Comment line - bail out of this hunk
|
||||
// break;
|
||||
// }
|
||||
|
||||
var actualLineNumber = hunk.diffStart + lineNumber;
|
||||
var isMergeHeader = isConflict && /^..(<<<<<<<|=======$|>>>>>>>)/.test(lineText);
|
||||
var diffRow = $('<tr>').appendTo(codeBody);
|
||||
var localLineNo = $('<td class="lineno">').appendTo(diffRow);
|
||||
var remoteLineNo;
|
||||
if (!isMergeHeader) {
|
||||
remoteLineNo = $('<td class="lineno">').appendTo(diffRow);
|
||||
} else {
|
||||
if (lineText[0] === '+' || (isConflict && lineText[1] === '+')) {
|
||||
localLineNo.addClass("added");
|
||||
remoteLineNo.addClass("added");
|
||||
line.addClass("added");
|
||||
remoteLineNo.text(remoteLine++);
|
||||
handledlLine = true;
|
||||
} else if (lineText[0] === '-' || (isConflict && lineText[1] === '-')) {
|
||||
localLineNo.addClass("removed");
|
||||
remoteLineNo.addClass("removed");
|
||||
line.addClass("removed");
|
||||
localLineNo.text(localLine++);
|
||||
handledlLine = true;
|
||||
}
|
||||
localLineNo.attr('colspan',2);
|
||||
}
|
||||
if (!handledlLine) {
|
||||
line.addClass("unchanged");
|
||||
if (localLine > 0 && lineText[0] !== '\\' && lineText !== "") {
|
||||
localLineNo.text(localLine++);
|
||||
}
|
||||
if (remoteLine > 0 && lineText[0] !== '\\' && lineText !== "") {
|
||||
remoteLineNo.text(remoteLine++);
|
||||
}
|
||||
var line = $('<td class="linetext">').appendTo(diffRow);
|
||||
var prefixStart = 0;
|
||||
var prefixEnd = 1;
|
||||
if (isConflict) {
|
||||
prefixEnd = 2;
|
||||
}
|
||||
$('<span>').text(lineText.substring(prefixEnd)).appendTo(line);
|
||||
} else {
|
||||
diffRow.addClass("mergeHeader");
|
||||
var isSeparator = /^..(=======$)/.test(lineText);
|
||||
if (!isSeparator) {
|
||||
var isOurs = /^..<<<<<<</.test(lineText);
|
||||
if (isOurs) {
|
||||
$('<span>').text("<<<<<<< Local Changes").appendTo(line);
|
||||
hunk.localChangeStart = actualLineNumber;
|
||||
if (!isMergeHeader) {
|
||||
var changeMarker = lineText[0];
|
||||
if (isConflict && !commitOptions.unmerged && changeMarker === ' ') {
|
||||
changeMarker = lineText[1];
|
||||
}
|
||||
$('<span class="prefix">').text(changeMarker).appendTo(line);
|
||||
var handledlLine = false;
|
||||
if (isConflict && commitOptions.unmerged) {
|
||||
$('<span class="prefix">').text(lineText[1]).appendTo(line);
|
||||
if (lineText[0] === '+') {
|
||||
localLineNo.text(localLine++);
|
||||
handledlLine = true;
|
||||
}
|
||||
if (lineText[1] === '+') {
|
||||
remoteLineNo.text(remoteLine++);
|
||||
handledlLine = true;
|
||||
}
|
||||
} else {
|
||||
hunk.remoteChangeEnd = actualLineNumber;
|
||||
$('<span>').text(">>>>>>> Remote Changes").appendTo(line);
|
||||
|
||||
if (lineText[0] === '+' || (isConflict && lineText[1] === '+')) {
|
||||
localLineNo.addClass("added");
|
||||
remoteLineNo.addClass("added");
|
||||
line.addClass("added");
|
||||
remoteLineNo.text(remoteLine++);
|
||||
handledlLine = true;
|
||||
} else if (lineText[0] === '-' || (isConflict && lineText[1] === '-')) {
|
||||
localLineNo.addClass("removed");
|
||||
remoteLineNo.addClass("removed");
|
||||
line.addClass("removed");
|
||||
localLineNo.text(localLine++);
|
||||
handledlLine = true;
|
||||
}
|
||||
}
|
||||
diffRow.addClass("mergeHeader-"+(isOurs?"ours":"theirs"));
|
||||
$('<button class="editor-button editor-button-small" style="float: right; margin-right: 20px;"><i class="fa fa-angle-double-'+(isOurs?"down":"up")+'"></i> use '+(isOurs?"local":"remote")+' changes</button>')
|
||||
.appendTo(line)
|
||||
.click(function(evt) {
|
||||
evt.preventDefault();
|
||||
resolvedConflicts++;
|
||||
var addedRows;
|
||||
var midRow;
|
||||
if (isOurs) {
|
||||
addedRows = diffRow.nextUntil(".mergeHeader-separator");
|
||||
midRow = addedRows.last().next();
|
||||
midRow.nextUntil(".mergeHeader").remove();
|
||||
midRow.next().remove();
|
||||
} else {
|
||||
addedRows = diffRow.prevUntil(".mergeHeader-separator");
|
||||
midRow = addedRows.last().prev();
|
||||
midRow.prevUntil(".mergeHeader").remove();
|
||||
midRow.prev().remove();
|
||||
}
|
||||
midRow.remove();
|
||||
diffRow.remove();
|
||||
addedRows.find(".linetext").addClass('added');
|
||||
conflictHeader.empty();
|
||||
$('<span><span>'+resolvedConflicts+'</span> of <span>'+unresolvedConflicts+'</span> conflicts resolved</span>').appendTo(conflictHeader);
|
||||
|
||||
conflictResolutions[file.file] = conflictResolutions[file.file] || {};
|
||||
conflictResolutions[file.file][hunk.localChangeStart] = {
|
||||
changeStart: hunk.localChangeStart,
|
||||
separator: hunk.changeSeparator,
|
||||
changeEnd: hunk.remoteChangeEnd,
|
||||
selection: isOurs?"A":"B"
|
||||
}
|
||||
if (commitOptions.resolveConflict) {
|
||||
commitOptions.resolveConflict({
|
||||
conflicts: unresolvedConflicts,
|
||||
resolved: resolvedConflicts,
|
||||
resolutions: conflictResolutions
|
||||
});
|
||||
}
|
||||
})
|
||||
if (!handledlLine) {
|
||||
line.addClass("unchanged");
|
||||
if (localLine > 0 && lineText[0] !== '\\' && lineText !== "") {
|
||||
localLineNo.text(localLine++);
|
||||
}
|
||||
if (remoteLine > 0 && lineText[0] !== '\\' && lineText !== "") {
|
||||
remoteLineNo.text(remoteLine++);
|
||||
}
|
||||
}
|
||||
$('<span>').text(lineText.substring(prefixEnd)).appendTo(line);
|
||||
} else {
|
||||
hunk.changeSeparator = actualLineNumber;
|
||||
diffRow.addClass("mergeHeader-separator");
|
||||
diffRow.addClass("mergeHeader");
|
||||
var isSeparator = /^..(=======$)/.test(lineText);
|
||||
if (!isSeparator) {
|
||||
var isOurs = /^..<<<<<<</.test(lineText);
|
||||
if (isOurs) {
|
||||
$('<span>').text("<<<<<<< Local Changes").appendTo(line);
|
||||
hunk.localChangeStart = actualLineNumber;
|
||||
} else {
|
||||
hunk.remoteChangeEnd = actualLineNumber;
|
||||
$('<span>').text(">>>>>>> Remote Changes").appendTo(line);
|
||||
|
||||
}
|
||||
diffRow.addClass("mergeHeader-"+(isOurs?"ours":"theirs"));
|
||||
$('<button class="editor-button editor-button-small" style="float: right; margin-right: 20px;"><i class="fa fa-angle-double-'+(isOurs?"down":"up")+'"></i> use '+(isOurs?"local":"remote")+' changes</button>')
|
||||
.appendTo(line)
|
||||
.click(function(evt) {
|
||||
evt.preventDefault();
|
||||
resolvedConflicts++;
|
||||
var addedRows;
|
||||
var midRow;
|
||||
if (isOurs) {
|
||||
addedRows = diffRow.nextUntil(".mergeHeader-separator");
|
||||
midRow = addedRows.last().next();
|
||||
midRow.nextUntil(".mergeHeader").remove();
|
||||
midRow.next().remove();
|
||||
} else {
|
||||
addedRows = diffRow.prevUntil(".mergeHeader-separator");
|
||||
midRow = addedRows.last().prev();
|
||||
midRow.prevUntil(".mergeHeader").remove();
|
||||
midRow.prev().remove();
|
||||
}
|
||||
midRow.remove();
|
||||
diffRow.remove();
|
||||
addedRows.find(".linetext").addClass('added');
|
||||
conflictHeader.empty();
|
||||
$('<span><span>'+resolvedConflicts+'</span> of <span>'+unresolvedConflicts+'</span> conflicts resolved</span>').appendTo(conflictHeader);
|
||||
|
||||
conflictResolutions[file.file] = conflictResolutions[file.file] || {};
|
||||
conflictResolutions[file.file][hunk.localChangeStart] = {
|
||||
changeStart: hunk.localChangeStart,
|
||||
separator: hunk.changeSeparator,
|
||||
changeEnd: hunk.remoteChangeEnd,
|
||||
selection: isOurs?"A":"B"
|
||||
}
|
||||
if (commitOptions.resolveConflict) {
|
||||
commitOptions.resolveConflict({
|
||||
conflicts: unresolvedConflicts,
|
||||
resolved: resolvedConflicts,
|
||||
resolutions: conflictResolutions
|
||||
});
|
||||
}
|
||||
})
|
||||
} else {
|
||||
hunk.changeSeparator = actualLineNumber;
|
||||
diffRow.addClass("mergeHeader-separator");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
if (commitOptions.unmerged) {
|
||||
conflictHeader = $('<span style="float: right;"><span>'+resolvedConflicts+'</span> of <span>'+unresolvedConflicts+'</span> conflicts resolved</span>').appendTo(content);
|
||||
}
|
||||
@@ -2041,7 +2048,9 @@ RED.diff = (function() {
|
||||
} else {
|
||||
lines = diff.split("\n");
|
||||
}
|
||||
var diffHeader = /^diff --git a\/(.*) b\/(.*)$/;
|
||||
var fileHeader = /^\+\+\+ b\/(.*)\t?/;
|
||||
var binaryFile = /^Binary files /;
|
||||
var hunkHeader = /^@@ -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @@ ?(.*)$/;
|
||||
var conflictHunkHeader = /^@+ -((\d+)(,(\d+))?) -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @+/;
|
||||
var files = [];
|
||||
@@ -2050,16 +2059,21 @@ RED.diff = (function() {
|
||||
var currentHunk;
|
||||
for (var i=0;i<lines.length;i++) {
|
||||
var line = lines[i];
|
||||
if (/^diff/.test(line)) {
|
||||
var diffLine = diffHeader.exec(line);
|
||||
if (diffLine) {
|
||||
if (currentHunk) {
|
||||
currentFile.hunks.push(currentHunk);
|
||||
files.push(currentFile);
|
||||
}
|
||||
currentHunk = null;
|
||||
currentFile = {
|
||||
file: null,
|
||||
file: diffLine[1],
|
||||
hunks: []
|
||||
}
|
||||
} else if (binaryFile.test(line)) {
|
||||
if (currentFile) {
|
||||
currentFile.binary = true;
|
||||
}
|
||||
} else {
|
||||
var fileLine = fileHeader.exec(line);
|
||||
if (fileLine) {
|
||||
@@ -2106,8 +2120,8 @@ RED.diff = (function() {
|
||||
}
|
||||
if (currentHunk) {
|
||||
currentFile.hunks.push(currentHunk);
|
||||
files.push(currentFile);
|
||||
}
|
||||
files.push(currentFile);
|
||||
return files;
|
||||
}
|
||||
|
||||
|
@@ -26,10 +26,7 @@ RED.notify = (function() {
|
||||
}
|
||||
|
||||
if (options.modal) {
|
||||
$("#header-shade").show();
|
||||
$("#editor-shade").show();
|
||||
$("#palette-shade").show();
|
||||
$(".sidebar-shade").show();
|
||||
$("#full-shade").show();
|
||||
}
|
||||
|
||||
if (currentNotifications.length > 4) {
|
||||
@@ -77,10 +74,7 @@ RED.notify = (function() {
|
||||
nn.parentNode.removeChild(nn);
|
||||
});
|
||||
if (options.modal) {
|
||||
$("#header-shade").hide();
|
||||
$("#editor-shade").hide();
|
||||
$("#palette-shade").hide();
|
||||
$(".sidebar-shade").hide();
|
||||
$("#full-shade").hide();
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
@@ -134,6 +134,7 @@ RED.projects.settings = (function() {
|
||||
},
|
||||
200: function(data) {
|
||||
done(null,data);
|
||||
RED.sidebar.versionControl.refresh(true);
|
||||
},
|
||||
400: {
|
||||
'unexpected_error': function(error) {
|
||||
@@ -197,6 +198,7 @@ RED.projects.settings = (function() {
|
||||
done(error,null);
|
||||
},
|
||||
200: function(data) {
|
||||
RED.sidebar.versionControl.refresh(true);
|
||||
done(null,data);
|
||||
},
|
||||
400: {
|
||||
@@ -326,6 +328,7 @@ RED.projects.settings = (function() {
|
||||
done(error,null);
|
||||
},
|
||||
200: function(data) {
|
||||
RED.sidebar.versionControl.refresh(true);
|
||||
done(null,data);
|
||||
},
|
||||
400: {
|
||||
@@ -900,6 +903,7 @@ RED.projects.settings = (function() {
|
||||
},
|
||||
200: function(data) {
|
||||
activeProject = data;
|
||||
RED.sidebar.versionControl.refresh(true);
|
||||
updateForm();
|
||||
done();
|
||||
},
|
||||
@@ -947,8 +951,132 @@ RED.projects.settings = (function() {
|
||||
updateForm();
|
||||
}
|
||||
|
||||
function createLocalBranchListSection(activeProject,pane) {
|
||||
var localBranchContainer = $('<div class="user-settings-section"></div>').appendTo(pane);
|
||||
$('<h4></h4>').text("Branches").appendTo(localBranchContainer);
|
||||
|
||||
var row = $('<div class="user-settings-row projects-dialog-branch-list"></div>').appendTo(localBranchContainer);
|
||||
|
||||
|
||||
var branchList = $('<ol>').appendTo(row).editableList({
|
||||
addButton: false,
|
||||
scrollOnAdd: false,
|
||||
addItem: function(row,index,entry) {
|
||||
var container = $('<div class="projects-dialog-branch-list-entry">').appendTo(row);
|
||||
$('<span><i class="fa fa-code-fork"></i></span>').appendTo(container);
|
||||
$('<span class="branch-name">').text(entry.name).appendTo(container);
|
||||
// if (entry.commit) {
|
||||
// $('<span class="commit">').text(entry.commit.sha).appendTo(container);
|
||||
// }
|
||||
|
||||
if (entry.remote) {
|
||||
$('<span class="branch-remote-name">').text(entry.remote||"").appendTo(container);
|
||||
if (entry.status.ahead+entry.status.behind > 0) {
|
||||
$('<span class="branch-remote-status">'+
|
||||
'<i class="fa fa-long-arrow-up"></i> <span>'+entry.status.ahead+'</span> '+
|
||||
'<i class="fa fa-long-arrow-down"></i> <span>'+entry.status.behind+'</span>'+
|
||||
'</span>').appendTo(container);
|
||||
}
|
||||
}
|
||||
|
||||
var tools = $('<span class="projects-dialog-branch-list-entry-tools">').appendTo(container);
|
||||
if (entry.current) {
|
||||
tools.text('current');
|
||||
} else {
|
||||
$('<button class="editor-button editor-button-small">delete</button>')
|
||||
.appendTo(tools)
|
||||
.click(function(e) {
|
||||
e.preventDefault();
|
||||
var spinner = utils.addSpinnerOverlay(row).addClass('projects-dialog-spinner-contain');
|
||||
var notification = RED.notify("Are you sure you want to delete the local branch '"+entry.name+"'? This cannot be undone.", {
|
||||
type: "warning",
|
||||
modal: true,
|
||||
fixed: true,
|
||||
buttons: [
|
||||
{
|
||||
text: RED._("common.label.cancel"),
|
||||
click: function() {
|
||||
spinner.remove();
|
||||
notification.close();
|
||||
}
|
||||
},{
|
||||
text: 'Delete branch',
|
||||
click: function() {
|
||||
notification.close();
|
||||
var url = "projects/"+activeProject.name+"/branches/"+entry.name;
|
||||
var options = {
|
||||
url: url,
|
||||
type: "DELETE",
|
||||
responses: {
|
||||
200: function(data) {
|
||||
row.fadeOut(200,function() {
|
||||
branchList.editableList('removeItem',entry);
|
||||
spinner.remove();
|
||||
});
|
||||
},
|
||||
400: {
|
||||
'git_delete_branch_unmerged': function(error) {
|
||||
notification = RED.notify("The local branch '"+entry.name+"' has unmerged changes that will be lost. Are you sure you want to delete it?", {
|
||||
type: "warning",
|
||||
modal: true,
|
||||
fixed: true,
|
||||
buttons: [
|
||||
{
|
||||
text: RED._("common.label.cancel"),
|
||||
click: function() {
|
||||
spinner.remove();
|
||||
notification.close();
|
||||
}
|
||||
},{
|
||||
text: 'Delete unmerged branch',
|
||||
click: function() {
|
||||
options.url += "?force=true";
|
||||
notification.close();
|
||||
utils.sendRequest(options);
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
},
|
||||
'unexpected_error': function(error) {
|
||||
console.log(error);
|
||||
spinner.remove();
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
utils.sendRequest(options);
|
||||
}
|
||||
}
|
||||
|
||||
]
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
$.getJSON("projects/"+activeProject.name+"/branches",function(result) {
|
||||
if (result.branches) {
|
||||
result.branches.sort(function(A,B) {
|
||||
if (A.current) { return -1 }
|
||||
if (B.current) { return 1 }
|
||||
return A.name.localeCompare(B.name);
|
||||
});
|
||||
result.branches.forEach(function(branch) {
|
||||
branchList.editableList('addItem',branch);
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
function createRemoteRepositorySection(activeProject,pane) {
|
||||
var title = $('<h3></h3>').text("Version Control").appendTo(pane);
|
||||
$('<h3></h3>').text("Version Control").appendTo(pane);
|
||||
|
||||
createLocalBranchListSection(activeProject,pane);
|
||||
|
||||
var repoContainer = $('<div class="user-settings-section"></div>').appendTo(pane);
|
||||
var title = $('<h4></h4>').text("Git remotes").appendTo(repoContainer);
|
||||
|
||||
var editRepoButton = $('<button class="editor-button editor-button-small" style="float: right;">edit</button>')
|
||||
.appendTo(title)
|
||||
.click(function(evt) {
|
||||
@@ -958,9 +1086,9 @@ RED.projects.settings = (function() {
|
||||
$('.projects-dialog-remote-list-entry-delete').show();
|
||||
remoteListAddButton.show();
|
||||
});
|
||||
|
||||
var repoContainer = $('<div class="user-settings-section"></div>').appendTo(pane);
|
||||
var grTitle = $('<h4></h4>').text("Git remotes").appendTo(repoContainer);
|
||||
|
||||
|
||||
|
||||
|
||||
row = $('<div class="user-settings-row projects-dialog-remote-list"></div>').appendTo(repoContainer);
|
||||
var remotesList = $('<ol>').appendTo(row);
|
||||
|
@@ -615,7 +615,7 @@ RED.projects = (function() {
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -980,7 +980,6 @@ RED.projects = (function() {
|
||||
var branchFilterTerm = "";
|
||||
var branchFilterCreateItem;
|
||||
var branches = [];
|
||||
var currentBranch;
|
||||
var branchPrefix = "";
|
||||
var container = $('<div class="projects-branch-list">').appendTo(options.container);
|
||||
|
||||
@@ -1010,15 +1009,15 @@ RED.projects = (function() {
|
||||
scrollOnAdd: false,
|
||||
addItem: function(row,index,entry) {
|
||||
var container = $('<div class="sidebar-version-control-branch-list-entry">').appendTo(row);
|
||||
if (typeof entry !== "string") {
|
||||
if (!entry.hasOwnProperty('commit')) {
|
||||
branchFilterCreateItem = container;
|
||||
$('<i class="fa fa-code-fork"></i>').appendTo(container);
|
||||
$('<span>').text("Create branch:").appendTo(container);
|
||||
$('<div class="sidebar-version-control-branch-list-entry-create-name" style="margin-left: 10px;">').text(entry.name).appendTo(container);
|
||||
} else {
|
||||
$('<i class="fa fa-code-fork"></i>').appendTo(container);
|
||||
$('<span>').text(entry).appendTo(container);
|
||||
if (currentBranch === entry) {
|
||||
$('<span>').text(entry.name).appendTo(container);
|
||||
if (entry.current) {
|
||||
container.addClass("selected");
|
||||
$('<span class="current"></span>').text(options.currentLabel||"current").appendTo(container);
|
||||
}
|
||||
@@ -1029,7 +1028,7 @@ RED.projects = (function() {
|
||||
return;
|
||||
}
|
||||
var body = {};
|
||||
if (typeof entry !== "string") {
|
||||
if (!entry.hasOwnProperty('commit')) {
|
||||
body.name = branchFilter.val();
|
||||
body.create = true;
|
||||
if (options.remote) {
|
||||
@@ -1039,7 +1038,7 @@ RED.projects = (function() {
|
||||
if ($(this).hasClass('selected')) {
|
||||
body.current = true;
|
||||
}
|
||||
body.name = entry;
|
||||
body.name = entry.name;
|
||||
}
|
||||
if (options.onselect) {
|
||||
options.onselect(body);
|
||||
@@ -1047,7 +1046,7 @@ RED.projects = (function() {
|
||||
});
|
||||
},
|
||||
filter: function(data) {
|
||||
var isCreateEntry = (typeof data !=="string");
|
||||
var isCreateEntry = (!data.hasOwnProperty('commit'));
|
||||
return (
|
||||
isCreateEntry &&
|
||||
(
|
||||
@@ -1057,7 +1056,7 @@ RED.projects = (function() {
|
||||
) ||
|
||||
(
|
||||
!isCreateEntry &&
|
||||
data.indexOf(branchFilterTerm) !== -1
|
||||
data.name.indexOf(branchFilterTerm) !== -1
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -1067,14 +1066,12 @@ RED.projects = (function() {
|
||||
branchList.editableList('empty');
|
||||
var start = Date.now();
|
||||
var spinner = addSpinnerOverlay(container).addClass("projects-dialog-spinner-contain");
|
||||
currentBranch = options.current();
|
||||
if (options.remote) {
|
||||
branchPrefix = options.remote()+"/";
|
||||
} else {
|
||||
branchPrefix = "";
|
||||
}
|
||||
|
||||
|
||||
sendRequest({
|
||||
url: url,
|
||||
type: "GET",
|
||||
@@ -1100,7 +1097,7 @@ RED.projects = (function() {
|
||||
}
|
||||
})
|
||||
},
|
||||
addItem: function(data) { branchList.editableList('addItem',data) },
|
||||
// addItem: function(data) { branchList.editableList('addItem',data) },
|
||||
filter: function() { branchList.editableList('filter') },
|
||||
focus: function() { branchFilter.focus() }
|
||||
}
|
||||
|
@@ -39,7 +39,82 @@ RED.sidebar.versionControl = (function() {
|
||||
|
||||
var isMerging;
|
||||
|
||||
// TODO: DRY projectSummary.js
|
||||
function viewFileDiff(entry,state) {
|
||||
var activeProject = RED.projects.getActiveProject();
|
||||
var diffTarget = (state === 'staged')?"index":"tree";
|
||||
utils.sendRequest({
|
||||
url: "projects/"+activeProject.name+"/diff/"+diffTarget+"/"+encodeURIComponent(entry.file),
|
||||
type: "GET",
|
||||
responses: {
|
||||
0: function(error) {
|
||||
console.log(error);
|
||||
// done(error,null);
|
||||
},
|
||||
200: function(data) {
|
||||
if (mergeConflictNotification) {
|
||||
mergeConflictNotification.close();
|
||||
mergeConflictNotification = null;
|
||||
}
|
||||
var title;
|
||||
if (state === 'unstaged') {
|
||||
title = 'Unstaged changes : '+entry.file
|
||||
} else if (state === 'staged') {
|
||||
title = 'Staged changes : '+entry.file
|
||||
} else {
|
||||
title = 'Resolve conflicts : '+entry.file
|
||||
}
|
||||
var options = {
|
||||
diff: data.diff,
|
||||
title: title,
|
||||
unmerged: state === 'unmerged',
|
||||
project: activeProject
|
||||
}
|
||||
if (state == 'unstaged') {
|
||||
options.oldRevTitle = entry.indexStatus === " "?"HEAD":"Staged";
|
||||
options.newRevTitle = "Unstaged";
|
||||
options.oldRev = entry.indexStatus === " "?"@":":0";
|
||||
options.newRev = "_";
|
||||
} else if (state === 'staged') {
|
||||
options.oldRevTitle = "HEAD";
|
||||
options.newRevTitle = "Staged";
|
||||
options.oldRev = "@";
|
||||
options.newRev = ":0";
|
||||
} else {
|
||||
options.onresolve = function(resolution) {
|
||||
utils.sendRequest({
|
||||
url: "projects/"+activeProject.name+"/resolve/"+encodeURIComponent(entry.file),
|
||||
type: "POST",
|
||||
responses: {
|
||||
0: function(error) {
|
||||
console.log(error);
|
||||
// done(error,null);
|
||||
},
|
||||
200: function(data) {
|
||||
refresh(true);
|
||||
},
|
||||
400: {
|
||||
'unexpected_error': function(error) {
|
||||
console.log(error);
|
||||
// done(error,null);
|
||||
}
|
||||
},
|
||||
}
|
||||
},{resolutions:resolution.resolutions[entry.file]});
|
||||
}
|
||||
}
|
||||
options.oncancel = showMergeConflictNotification;
|
||||
RED.diff.showUnifiedDiff(options);
|
||||
// console.log(data.diff);
|
||||
},
|
||||
400: {
|
||||
'unexpected_error': function(error) {
|
||||
console.log(error);
|
||||
// done(error,null);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function createChangeEntry(row, entry, status, state) {
|
||||
row.addClass("sidebar-version-control-change-entry");
|
||||
@@ -52,88 +127,67 @@ RED.sidebar.versionControl = (function() {
|
||||
|
||||
|
||||
var icon = $('<i class=""></i>').appendTo(container);
|
||||
var label = $('<span>').appendTo(container);
|
||||
var entryLink = $('<a href="#">')
|
||||
.appendTo(container)
|
||||
.click(function(e) {
|
||||
e.preventDefault();
|
||||
viewFileDiff(entry,state);
|
||||
});
|
||||
var label = $('<span>').appendTo(entryLink);
|
||||
|
||||
var bg = $('<div class="button-group"></div>').appendTo(row);
|
||||
var viewDiffButton = $('<button class="editor-button editor-button-small"><i class="fa fa-'+(state==='unmerged'?'columns':'eye')+'"></i></button>')
|
||||
.appendTo(bg)
|
||||
.click(function(evt) {
|
||||
evt.preventDefault();
|
||||
var activeProject = RED.projects.getActiveProject();
|
||||
var diffTarget = (state === 'staged')?"index":"tree";
|
||||
utils.sendRequest({
|
||||
url: "projects/"+activeProject.name+"/diff/"+diffTarget+"/"+encodeURIComponent(entry.file),
|
||||
type: "GET",
|
||||
responses: {
|
||||
0: function(error) {
|
||||
console.log(error);
|
||||
// done(error,null);
|
||||
},
|
||||
200: function(data) {
|
||||
if (mergeConflictNotification) {
|
||||
mergeConflictNotification.close();
|
||||
mergeConflictNotification = null;
|
||||
}
|
||||
var title;
|
||||
if (state === 'unstaged') {
|
||||
title = 'Unstaged changes : '+entry.file
|
||||
} else if (state === 'staged') {
|
||||
title = 'Staged changes : '+entry.file
|
||||
} else {
|
||||
title = 'Resolve conflicts : '+entry.file
|
||||
}
|
||||
var options = {
|
||||
diff: data.diff,
|
||||
title: title,
|
||||
unmerged: state === 'unmerged',
|
||||
project: activeProject
|
||||
}
|
||||
if (state == 'unstaged') {
|
||||
options.oldRevTitle = entry.indexStatus === " "?"HEAD":"Staged";
|
||||
options.newRevTitle = "Unstaged";
|
||||
options.oldRev = entry.indexStatus === " "?"@":":0";
|
||||
options.newRev = "_";
|
||||
} else if (state === 'staged') {
|
||||
options.oldRevTitle = "HEAD";
|
||||
options.newRevTitle = "Staged";
|
||||
options.oldRev = "@";
|
||||
options.newRev = ":0";
|
||||
} else {
|
||||
options.onresolve = function(resolution) {
|
||||
utils.sendRequest({
|
||||
url: "projects/"+activeProject.name+"/resolve/"+encodeURIComponent(entry.file),
|
||||
type: "POST",
|
||||
var entryTools = $('<div class="sidebar-version-control-change-entry-tools">').appendTo(row);
|
||||
var bg;
|
||||
var revertButton;
|
||||
if (state === 'unstaged') {
|
||||
bg = $('<span class="button-group" style="margin-right: 5px;"></span>').appendTo(entryTools);
|
||||
revertButton = $('<button class="editor-button editor-button-small"><i class="fa fa-reply"></i></button>')
|
||||
.appendTo(bg)
|
||||
.click(function(evt) {
|
||||
evt.preventDefault();
|
||||
var spinner = utils.addSpinnerOverlay(container).addClass('projects-dialog-spinner-contain');
|
||||
var notification = RED.notify("Are you sure you want to revert the changes to '"+entry.file+"'? This cannot be undone.", {
|
||||
type: "warning",
|
||||
modal: true,
|
||||
fixed: true,
|
||||
buttons: [
|
||||
{
|
||||
text: RED._("common.label.cancel"),
|
||||
click: function() {
|
||||
spinner.remove();
|
||||
notification.close();
|
||||
}
|
||||
},{
|
||||
text: 'Revert changes',
|
||||
click: function() {
|
||||
notification.close();
|
||||
var activeProject = RED.projects.getActiveProject();
|
||||
var url = "projects/"+activeProject.name+"/files/_/"+entry.file;
|
||||
var options = {
|
||||
url: url,
|
||||
type: "DELETE",
|
||||
responses: {
|
||||
0: function(error) {
|
||||
console.log(error);
|
||||
// done(error,null);
|
||||
},
|
||||
200: function(data) {
|
||||
refresh(true);
|
||||
spinner.remove();
|
||||
},
|
||||
400: {
|
||||
'unexpected_error': function(error) {
|
||||
spinner.remove();
|
||||
console.log(error);
|
||||
// done(error,null);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},{resolutions:resolution.resolutions[entry.file]});
|
||||
}
|
||||
utils.sendRequest(options);
|
||||
}
|
||||
}
|
||||
options.oncancel = showMergeConflictNotification;
|
||||
RED.diff.showUnifiedDiff(options);
|
||||
// console.log(data.diff);
|
||||
},
|
||||
400: {
|
||||
'unexpected_error': function(error) {
|
||||
console.log(error);
|
||||
// done(error,null);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
]
|
||||
})
|
||||
|
||||
});
|
||||
}
|
||||
bg = $('<span class="button-group"></span>').appendTo(entryTools);
|
||||
if (state !== 'unmerged') {
|
||||
$('<button class="editor-button editor-button-small"><i class="fa fa-'+((state==='unstaged')?"plus":"minus")+'"></i></button>')
|
||||
.appendTo(bg)
|
||||
@@ -203,11 +257,10 @@ RED.sidebar.versionControl = (function() {
|
||||
delete entry.spinner;
|
||||
}
|
||||
|
||||
viewDiffButton.attr("disabled",(status === 'D' || status === '?'));
|
||||
viewDiffButton.find("i")
|
||||
.toggleClass('fa-eye',!(status === 'D' || status === '?'))
|
||||
.toggleClass('fa-eye-slash',(status === 'D' || status === '?'))
|
||||
|
||||
if (revertButton) {
|
||||
revertButton.toggle(status !== '?');
|
||||
}
|
||||
entryLink.toggleClass("disabled",(status === 'D' || status === '?'));
|
||||
}
|
||||
entry["update"+((state==='unstaged')?"Unstaged":"Staged")](entry, status);
|
||||
}
|
||||
@@ -571,9 +624,6 @@ RED.sidebar.versionControl = (function() {
|
||||
$('<div class="sidebar-version-control-slide-box-header"></div>').text("Change local branch").appendTo(localBranchBox);
|
||||
|
||||
var localBranchList = utils.createBranchList({
|
||||
current: function() {
|
||||
return RED.projects.getActiveProject().git.branches.local
|
||||
},
|
||||
placeholder: "Find or create a branch",
|
||||
container: localBranchBox,
|
||||
onselect: function(body) {
|
||||
@@ -711,9 +761,6 @@ RED.sidebar.versionControl = (function() {
|
||||
|
||||
var remoteBranchSubRow = $('<div style="height: 0;overflow:hidden; transition: height 0.2s ease-in-out;"></div>').hide().appendTo(remoteBranchRow);
|
||||
var remoteBranchList = utils.createBranchList({
|
||||
current: function() {
|
||||
return RED.projects.getActiveProject().git.branches.remote
|
||||
},
|
||||
placeholder: "Find or create a remote branch",
|
||||
currentLabel: "upstream",
|
||||
remote: function() {
|
||||
|
Reference in New Issue
Block a user