mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add suitable message when not displaying binary files
This commit is contained in:
parent
bb59cd5742
commit
028d66befc
@ -1678,9 +1678,10 @@ RED.diff = (function() {
|
|||||||
|
|
||||||
function createUnifiedDiffTable(files,commitOptions) {
|
function createUnifiedDiffTable(files,commitOptions) {
|
||||||
var diffPanel = $('<div></div>');
|
var diffPanel = $('<div></div>');
|
||||||
|
console.log(files);
|
||||||
files.forEach(function(file) {
|
files.forEach(function(file) {
|
||||||
var hunks = file.hunks;
|
var hunks = file.hunks;
|
||||||
|
var isBinary = file.binary;
|
||||||
var codeTable = $("<table>").appendTo(diffPanel);
|
var codeTable = $("<table>").appendTo(diffPanel);
|
||||||
$('<colgroup><col width="50"><col width="50"><col width="100%"></colgroup>').appendTo(codeTable);
|
$('<colgroup><col width="50"><col width="50"><col width="100%"></colgroup>').appendTo(codeTable);
|
||||||
var codeBody = $('<tbody>').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) {
|
} else {
|
||||||
var diffRow = $('<tr class="node-text-diff-header">').appendTo(codeBody);
|
hunks.forEach(function(hunk) {
|
||||||
var content = $('<td colspan="3"></td>').appendTo(diffRow);
|
var diffRow = $('<tr class="node-text-diff-header">').appendTo(codeBody);
|
||||||
var label = $('<span></span>').text(hunk.header).appendTo(content);
|
var content = $('<td colspan="3"></td>').appendTo(diffRow);
|
||||||
var isConflict = hunk.conflict;
|
var label = $('<span></span>').text(hunk.header).appendTo(content);
|
||||||
var localLine = hunk.localStartLine;
|
var isConflict = hunk.conflict;
|
||||||
var remoteLine = hunk.remoteStartLine;
|
var localLine = hunk.localStartLine;
|
||||||
if (isConflict) {
|
var remoteLine = hunk.remoteStartLine;
|
||||||
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;
|
|
||||||
if (isConflict) {
|
if (isConflict) {
|
||||||
prefixEnd = 2;
|
unresolvedConflicts++;
|
||||||
}
|
}
|
||||||
if (!isMergeHeader) {
|
|
||||||
var changeMarker = lineText[0];
|
hunk.lines.forEach(function(lineText,lineNumber) {
|
||||||
if (isConflict && !commitOptions.unmerged && changeMarker === ' ') {
|
// if (lineText[0] === '\\' || lineText === "") {
|
||||||
changeMarker = lineText[1];
|
// // Comment line - bail out of this hunk
|
||||||
}
|
// break;
|
||||||
$('<span class="prefix">').text(changeMarker).appendTo(line);
|
// }
|
||||||
var handledlLine = false;
|
|
||||||
if (isConflict && commitOptions.unmerged) {
|
var actualLineNumber = hunk.diffStart + lineNumber;
|
||||||
$('<span class="prefix">').text(lineText[1]).appendTo(line);
|
var isMergeHeader = isConflict && /^..(<<<<<<<|=======$|>>>>>>>)/.test(lineText);
|
||||||
if (lineText[0] === '+') {
|
var diffRow = $('<tr>').appendTo(codeBody);
|
||||||
localLineNo.text(localLine++);
|
var localLineNo = $('<td class="lineno">').appendTo(diffRow);
|
||||||
handledlLine = true;
|
var remoteLineNo;
|
||||||
}
|
if (!isMergeHeader) {
|
||||||
if (lineText[1] === '+') {
|
remoteLineNo = $('<td class="lineno">').appendTo(diffRow);
|
||||||
remoteLineNo.text(remoteLine++);
|
|
||||||
handledlLine = true;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (lineText[0] === '+' || (isConflict && lineText[1] === '+')) {
|
localLineNo.attr('colspan',2);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!handledlLine) {
|
var line = $('<td class="linetext">').appendTo(diffRow);
|
||||||
line.addClass("unchanged");
|
var prefixStart = 0;
|
||||||
if (localLine > 0 && lineText[0] !== '\\' && lineText !== "") {
|
var prefixEnd = 1;
|
||||||
localLineNo.text(localLine++);
|
if (isConflict) {
|
||||||
}
|
prefixEnd = 2;
|
||||||
if (remoteLine > 0 && lineText[0] !== '\\' && lineText !== "") {
|
|
||||||
remoteLineNo.text(remoteLine++);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$('<span>').text(lineText.substring(prefixEnd)).appendTo(line);
|
if (!isMergeHeader) {
|
||||||
} else {
|
var changeMarker = lineText[0];
|
||||||
diffRow.addClass("mergeHeader");
|
if (isConflict && !commitOptions.unmerged && changeMarker === ' ') {
|
||||||
var isSeparator = /^..(=======$)/.test(lineText);
|
changeMarker = lineText[1];
|
||||||
if (!isSeparator) {
|
}
|
||||||
var isOurs = /^..<<<<<<</.test(lineText);
|
$('<span class="prefix">').text(changeMarker).appendTo(line);
|
||||||
if (isOurs) {
|
var handledlLine = false;
|
||||||
$('<span>').text("<<<<<<< Local Changes").appendTo(line);
|
if (isConflict && commitOptions.unmerged) {
|
||||||
hunk.localChangeStart = actualLineNumber;
|
$('<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 {
|
} else {
|
||||||
hunk.remoteChangeEnd = actualLineNumber;
|
if (lineText[0] === '+' || (isConflict && lineText[1] === '+')) {
|
||||||
$('<span>').text(">>>>>>> Remote Changes").appendTo(line);
|
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"));
|
if (!handledlLine) {
|
||||||
$('<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>')
|
line.addClass("unchanged");
|
||||||
.appendTo(line)
|
if (localLine > 0 && lineText[0] !== '\\' && lineText !== "") {
|
||||||
.click(function(evt) {
|
localLineNo.text(localLine++);
|
||||||
evt.preventDefault();
|
}
|
||||||
resolvedConflicts++;
|
if (remoteLine > 0 && lineText[0] !== '\\' && lineText !== "") {
|
||||||
var addedRows;
|
remoteLineNo.text(remoteLine++);
|
||||||
var midRow;
|
}
|
||||||
if (isOurs) {
|
}
|
||||||
addedRows = diffRow.nextUntil(".mergeHeader-separator");
|
$('<span>').text(lineText.substring(prefixEnd)).appendTo(line);
|
||||||
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 {
|
} else {
|
||||||
hunk.changeSeparator = actualLineNumber;
|
diffRow.addClass("mergeHeader");
|
||||||
diffRow.addClass("mergeHeader-separator");
|
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) {
|
if (commitOptions.unmerged) {
|
||||||
conflictHeader = $('<span style="float: right;"><span>'+resolvedConflicts+'</span> of <span>'+unresolvedConflicts+'</span> conflicts resolved</span>').appendTo(content);
|
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 {
|
} else {
|
||||||
lines = diff.split("\n");
|
lines = diff.split("\n");
|
||||||
}
|
}
|
||||||
|
var diffHeader = /^diff --git a\/(.*) b\/(.*)$/;
|
||||||
var fileHeader = /^\+\+\+ b\/(.*)\t?/;
|
var fileHeader = /^\+\+\+ b\/(.*)\t?/;
|
||||||
|
var binaryFile = /^Binary files /;
|
||||||
var hunkHeader = /^@@ -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @@ ?(.*)$/;
|
var hunkHeader = /^@@ -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @@ ?(.*)$/;
|
||||||
var conflictHunkHeader = /^@+ -((\d+)(,(\d+))?) -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @+/;
|
var conflictHunkHeader = /^@+ -((\d+)(,(\d+))?) -((\d+)(,(\d+))?) \+((\d+)(,(\d+))?) @+/;
|
||||||
var files = [];
|
var files = [];
|
||||||
@ -2050,16 +2059,21 @@ RED.diff = (function() {
|
|||||||
var currentHunk;
|
var currentHunk;
|
||||||
for (var i=0;i<lines.length;i++) {
|
for (var i=0;i<lines.length;i++) {
|
||||||
var line = lines[i];
|
var line = lines[i];
|
||||||
if (/^diff/.test(line)) {
|
var diffLine = diffHeader.exec(line);
|
||||||
|
if (diffLine) {
|
||||||
if (currentHunk) {
|
if (currentHunk) {
|
||||||
currentFile.hunks.push(currentHunk);
|
currentFile.hunks.push(currentHunk);
|
||||||
files.push(currentFile);
|
files.push(currentFile);
|
||||||
}
|
}
|
||||||
currentHunk = null;
|
currentHunk = null;
|
||||||
currentFile = {
|
currentFile = {
|
||||||
file: null,
|
file: diffLine[1],
|
||||||
hunks: []
|
hunks: []
|
||||||
}
|
}
|
||||||
|
} else if (binaryFile.test(line)) {
|
||||||
|
if (currentFile) {
|
||||||
|
currentFile.binary = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
var fileLine = fileHeader.exec(line);
|
var fileLine = fileHeader.exec(line);
|
||||||
if (fileLine) {
|
if (fileLine) {
|
||||||
@ -2106,8 +2120,8 @@ RED.diff = (function() {
|
|||||||
}
|
}
|
||||||
if (currentHunk) {
|
if (currentHunk) {
|
||||||
currentFile.hunks.push(currentHunk);
|
currentFile.hunks.push(currentHunk);
|
||||||
files.push(currentFile);
|
|
||||||
}
|
}
|
||||||
|
files.push(currentFile);
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user