Fix parsing of binary files
This commit is contained in:
parent
2f53bf777e
commit
9bbc87ae89
3 changed files with 27 additions and 4 deletions
|
|
@ -39,7 +39,7 @@
|
||||||
"release": "./scripts/release.sh",
|
"release": "./scripts/release.sh",
|
||||||
"release-bower": "./scripts/update-bower-version.sh",
|
"release-bower": "./scripts/update-bower-version.sh",
|
||||||
"templates": "./scripts/hulk.js --wrapper node --variable 'browserTemplates' ./src/templates/*.mustache > ./src/templates/diff2html-templates.js",
|
"templates": "./scripts/hulk.js --wrapper node --variable 'browserTemplates' ./src/templates/*.mustache > ./src/templates/diff2html-templates.js",
|
||||||
"style": "jscs src/*.js src/ui/js/*.js",
|
"style": "eslint src/*.js src/ui/js/*.js",
|
||||||
"coverage": "istanbul cover _mocha -- -u exports -R spec ./test/**/*",
|
"coverage": "istanbul cover _mocha -- -u exports -R spec ./test/**/*",
|
||||||
"check-coverage": "istanbul check-coverage --statements 90 --functions 90 --branches 85 --lines 90 ./coverage/coverage.json",
|
"check-coverage": "istanbul check-coverage --statements 90 --functions 90 --branches 85 --lines 90 ./coverage/coverage.json",
|
||||||
"test": "npm run style && npm run coverage && npm run check-coverage",
|
"test": "npm run style && npm run coverage && npm run check-coverage",
|
||||||
|
|
|
||||||
|
|
@ -211,10 +211,10 @@
|
||||||
*/
|
*/
|
||||||
if (
|
if (
|
||||||
(utils.startsWith(line, oldFileNameHeader) &&
|
(utils.startsWith(line, oldFileNameHeader) &&
|
||||||
utils.startsWith(nxtLine, newFileNameHeader) && utils.startsWith(afterNxtLine, hunkHeaderPrefix)) ||
|
utils.startsWith(nxtLine, newFileNameHeader)) ||
|
||||||
|
|
||||||
(utils.startsWith(line, newFileNameHeader) &&
|
(utils.startsWith(line, newFileNameHeader) &&
|
||||||
utils.startsWith(prevLine, oldFileNameHeader) && utils.startsWith(nxtLine, hunkHeaderPrefix))
|
utils.startsWith(prevLine, oldFileNameHeader))
|
||||||
) {
|
) {
|
||||||
/*
|
/*
|
||||||
* --- Date Timestamp[FractionalSeconds] TimeZone
|
* --- Date Timestamp[FractionalSeconds] TimeZone
|
||||||
|
|
@ -239,7 +239,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentFile && utils.startsWith(line, hunkHeaderPrefix)) {
|
if (
|
||||||
|
(currentFile && utils.startsWith(line, hunkHeaderPrefix)) ||
|
||||||
|
(currentFile.isGitDiff && currentFile && currentFile.oldName && currentFile.newName && !currentBlock)
|
||||||
|
) {
|
||||||
startBlock(line);
|
startBlock(line);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -523,5 +523,25 @@ describe('DiffParser', function() {
|
||||||
assert.deepEqual(linesContent, [' test']);
|
assert.deepEqual(linesContent, [' test']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should parse binary file diff', function() {
|
||||||
|
var diff =
|
||||||
|
'diff --git a/last-changes-config.png b/last-changes-config.png\n' +
|
||||||
|
'index 322248b..56fc1f2 100644\n' +
|
||||||
|
'--- a/last-changes-config.png\n' +
|
||||||
|
'+++ b/last-changes-config.png\n' +
|
||||||
|
'Binary files differ';
|
||||||
|
|
||||||
|
var result = DiffParser.generateDiffJson(diff);
|
||||||
|
var file1 = result[0];
|
||||||
|
assert.equal(1, result.length);
|
||||||
|
assert.equal(0, file1.addedLines);
|
||||||
|
assert.equal(0, file1.deletedLines);
|
||||||
|
assert.equal('last-changes-config.png', file1.oldName);
|
||||||
|
assert.equal('last-changes-config.png', file1.newName);
|
||||||
|
assert.equal(1, file1.blocks.length);
|
||||||
|
assert.equal(0, file1.blocks[0].lines.length);
|
||||||
|
assert.equal('Binary files differ', file1.blocks[0].header);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue