1
0
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:
Nick O'Leary 2017-12-11 17:05:27 +00:00
parent bb59cd5742
commit 028d66befc
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -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,7 +1745,12 @@ 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);
} else {
hunks.forEach(function(hunk) {
var diffRow = $('<tr class="node-text-diff-header">').appendTo(codeBody);
var content = $('<td colspan="3"></td>').appendTo(diffRow);
@ -1880,6 +1886,7 @@ RED.diff = (function() {
}
});
});
}
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;
}