From c1fcf6dd9cfaa7ed7e0d3ada466b58308e9fae95 Mon Sep 17 00:00:00 2001 From: Jinheng Zhu Date: Wed, 26 Apr 2017 11:22:39 +0800 Subject: [PATCH 1/8] Add support for output of `svn diff --git` --- README.md | 4 ++ src/diff-parser.js | 110 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 105 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b4b368e..68cd5df 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ diff2html generates pretty HTML diffs from git or unified diff output. * Easy code selection +* Support `svn diff --git` output + ## Online Example > Go to [diff2html](https://diff2html.xyz/) @@ -100,6 +102,8 @@ The HTML output accepts a Javascript object with configuration. Possible options - `matchingMaxComparisons`: perform at most this much comparisons for line matching a block of changes, default is `2500` - `templates`: object with previously compiled templates to replace parts of the html - `rawTemplates`: object with raw not compiled templates to replace parts of the html + - `ignoreSvnPropertyChange`: If you use `svn diff --git`, and add or delete a binary file, you will get two file change records in output. Set `ignoreSvnPropertyChange = true` will help you ignore the second record. + > For more information regarding the possible templates look into [src/templates](https://github.com/rtfpessoa/diff2html/tree/master/src/templates) ## Diff2HtmlUI Helper diff --git a/src/diff-parser.js b/src/diff-parser.js index 4f3fdf6..1b67feb 100644 --- a/src/diff-parser.js +++ b/src/diff-parser.js @@ -5,7 +5,7 @@ * */ -(function() { +(function () { var utils = require('./utils.js').Utils; var LINE_TYPE = { @@ -22,7 +22,7 @@ DiffParser.prototype.LINE_TYPE = LINE_TYPE; - DiffParser.prototype.generateDiffJson = function(diffInput, configuration) { + DiffParser.prototype.generateDiffJson = function (diffInput, configuration) { var config = configuration || {}; var files = []; @@ -198,8 +198,8 @@ /* Diff */ var oldMode = /^old mode (\d{6})/; var newMode = /^new mode (\d{6})/; - var deletedFileMode = /^deleted file mode (\d{6})/; - var newFileMode = /^new file mode (\d{6})/; + var deletedFileMode = /^deleted file mode (\d{5,6})/; + var newFileMode = /^new file mode (\d{5,6})/; var copyFrom = /^copy from "?(.+)"?/; var copyTo = /^copy to "?(.+)"?/; @@ -220,7 +220,45 @@ var combinedNewFile = /^new file mode (\d{6})/; var combinedDeletedFile = /^deleted file mode (\d{6}),(\d{6})/; - diffLines.forEach(function(line, lineIndex) { + var svnNullFileMode = /^(.+)(\s+)(\(nonexistent\))$/; + var svnWithVersionFileMode = /^(.+)(\s+)(\(revision\s+\d+\))$/; + + /* if we use command `svn diff --git`. we wiil get header like that: + * + * ``` + * diff --git a/color_doc.docx b/color_doc.docx + * --- a/color_doc.docx (nonexistent) + * +++ b/color_doc.docx (revision 10) + * ``` + * + * `(nonexistent)` means that file do not exist. + * `(revision 10)` shows the current version of file. When the string exit, this file is in reposity. + */ + function checkSvnFileMode(fileName, isOld) { + var result = null; + if (isOld) { + if (result = svnNullFileMode.exec(fileName)) { + currentFile.oldName = result[1]; + // currentFile.isNew = true; + } else if (result = svnWithVersionFileMode.exec(fileName)) { + currentFile.oldName = result[1]; + } else { + currentFile.oldName = fileName; + } + } else { + if (result = svnNullFileMode.exec(fileName)) { + currentFile.newName = result[1]; + // currentFile.isDeleted = true; + } else if (result = svnWithVersionFileMode.exec(fileName)) { + currentFile.newName = result[1]; + } else { + currentFile.newName = fileName; + } + + } + } + + diffLines.forEach(function (line, lineIndex) { // Unmerged paths, and possibly other non-diffable files // https://github.com/scottgonzalez/pretty-diff/issues/11 // Also, remove some useless lines @@ -280,7 +318,9 @@ */ if (currentFile && !currentFile.oldName && utils.startsWith(line, '--- ') && (values = getSrcFilename(line, config))) { - currentFile.oldName = values; + + checkSvnFileMode(values, true); + // currentFile.oldName = values; currentFile.language = getExtension(currentFile.oldName, currentFile.language); return; } @@ -291,7 +331,8 @@ */ if (currentFile && !currentFile.newName && utils.startsWith(line, '+++ ') && (values = getDstFilename(line, config))) { - currentFile.newName = values; + checkSvnFileMode(values, false); + // currentFile.newName = values; currentFile.language = getExtension(currentFile.newName, currentFile.language); return; } @@ -386,9 +427,57 @@ saveBlock(); saveFile(); + if (configuration.ignoreSvnPropertyChange) + files = dropSvnPropertyChangeFiles(files); return files; }; + /** + * If you use `svn diff --git`, and add or delete a binary file, you will get two file change records in output, like that: + * + * ``` + * =================================================================== + * diff --git a/text.png b/text.png + * deleted file mode 10644 + * GIT binary patch + * ... + * =================================================================== + * diff --git a/text.png b/text.png + * --- a/text.png (revision 15) + * +++ b/text.png (nonexistent) + * + * Property changes on: text.png + * ... + * ``` + * First record for "delete/new" a file. + * Second record for svn property change. + * + * You proberly do not want to see the second record. So will provide an `ignoreSvnPropertyChange` option to do that for you. + */ + function dropSvnPropertyChangeFiles(files) { + const GIT_BINNARY_HEADER = 'GIT binary patch'; + const PROPERTY_CHANGE_HEADER = 'Property changes on:'; + let ret = new Array(); + for (var i = 0; i < files.length - 1; i++) { + let file = files[i]; + let nextFile = files[i + 1]; + + ret.push(file); + if (file.blocks.length > 0 + && utils.startsWith(file.blocks[0].header, GIT_BINNARY_HEADER) + && nextFile.blocks.length > 0 + && utils.startsWith(nextFile.blocks[0].header, PROPERTY_CHANGE_HEADER) + && file.name === nextFile.name + && (file.isDeleted === true || file.isNew === true) + ) { + i += 1; + } + } + + return ret; + } + + function getExtension(filename, language) { var nameSplit = filename.split('.'); if (nameSplit.length > 1) { @@ -398,6 +487,7 @@ return language; } + function getSrcFilename(line, cfg) { return _getFilename('---', line, cfg.srcPrefix); } @@ -423,7 +513,7 @@ var values = FilenameRegExp.exec(line); if (values && values[1]) { filename = values[1]; - var matchingPrefixes = prefixes.filter(function(p) { + var matchingPrefixes = prefixes.filter(function (p) { return filename.indexOf(p) === 0; }); @@ -442,4 +532,6 @@ } module.exports.DiffParser = new DiffParser(); -})(); +}) +(); + From 3c8199a465665b4753e5bba082ecedc001f96025 Mon Sep 17 00:00:00 2001 From: Jinheng Zhu Date: Wed, 26 Apr 2017 11:39:47 +0800 Subject: [PATCH 2/8] change `let` to `var` --- src/diff-parser.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diff-parser.js b/src/diff-parser.js index 1b67feb..08d190d 100644 --- a/src/diff-parser.js +++ b/src/diff-parser.js @@ -457,10 +457,10 @@ function dropSvnPropertyChangeFiles(files) { const GIT_BINNARY_HEADER = 'GIT binary patch'; const PROPERTY_CHANGE_HEADER = 'Property changes on:'; - let ret = new Array(); + var ret = new Array(); for (var i = 0; i < files.length - 1; i++) { - let file = files[i]; - let nextFile = files[i + 1]; + var file = files[i]; + var nextFile = files[i + 1]; ret.push(file); if (file.blocks.length > 0 From a7b2a2048018018032f283d93cae30333646c88e Mon Sep 17 00:00:00 2001 From: Jinheng Zhu Date: Wed, 26 Apr 2017 12:06:36 +0800 Subject: [PATCH 3/8] change to Meet the requirements of `npm run style` --- src/diff-parser.js | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/diff-parser.js b/src/diff-parser.js index 08d190d..2d5a9b9 100644 --- a/src/diff-parser.js +++ b/src/diff-parser.js @@ -5,7 +5,7 @@ * */ -(function () { +(function() { var utils = require('./utils.js').Utils; var LINE_TYPE = { @@ -22,7 +22,7 @@ DiffParser.prototype.LINE_TYPE = LINE_TYPE; - DiffParser.prototype.generateDiffJson = function (diffInput, configuration) { + DiffParser.prototype.generateDiffJson = function(diffInput, configuration) { var config = configuration || {}; var files = []; @@ -237,28 +237,27 @@ function checkSvnFileMode(fileName, isOld) { var result = null; if (isOld) { - if (result = svnNullFileMode.exec(fileName)) { + if ((result = svnNullFileMode.exec(fileName))) { currentFile.oldName = result[1]; // currentFile.isNew = true; - } else if (result = svnWithVersionFileMode.exec(fileName)) { + } else if ((result = svnWithVersionFileMode.exec(fileName))) { currentFile.oldName = result[1]; } else { currentFile.oldName = fileName; } } else { - if (result = svnNullFileMode.exec(fileName)) { + if ((result = svnNullFileMode.exec(fileName))) { currentFile.newName = result[1]; // currentFile.isDeleted = true; - } else if (result = svnWithVersionFileMode.exec(fileName)) { + } else if ((result = svnWithVersionFileMode.exec(fileName))) { currentFile.newName = result[1]; } else { currentFile.newName = fileName; } - } } - diffLines.forEach(function (line, lineIndex) { + diffLines.forEach(function(line, lineIndex) { // Unmerged paths, and possibly other non-diffable files // https://github.com/scottgonzalez/pretty-diff/issues/11 // Also, remove some useless lines @@ -317,8 +316,9 @@ * --- 2002-02-21 23:30:39.942229878 -0800 */ if (currentFile && !currentFile.oldName && - utils.startsWith(line, '--- ') && (values = getSrcFilename(line, config))) { - + utils.startsWith(line, '--- ') && + (values = getSrcFilename(line, config)) + ) { checkSvnFileMode(values, true); // currentFile.oldName = values; currentFile.language = getExtension(currentFile.oldName, currentFile.language); @@ -427,8 +427,9 @@ saveBlock(); saveFile(); - if (configuration.ignoreSvnPropertyChange) + if (config.ignoreSvnPropertyChange) { files = dropSvnPropertyChangeFiles(files); + } return files; }; @@ -457,18 +458,18 @@ function dropSvnPropertyChangeFiles(files) { const GIT_BINNARY_HEADER = 'GIT binary patch'; const PROPERTY_CHANGE_HEADER = 'Property changes on:'; - var ret = new Array(); + var ret = []; for (var i = 0; i < files.length - 1; i++) { var file = files[i]; var nextFile = files[i + 1]; ret.push(file); - if (file.blocks.length > 0 - && utils.startsWith(file.blocks[0].header, GIT_BINNARY_HEADER) - && nextFile.blocks.length > 0 - && utils.startsWith(nextFile.blocks[0].header, PROPERTY_CHANGE_HEADER) - && file.name === nextFile.name - && (file.isDeleted === true || file.isNew === true) + if (file.blocks.length > 0 && + utils.startsWith(file.blocks[0].header, GIT_BINNARY_HEADER) && + nextFile.blocks.length > 0 && + utils.startsWith(nextFile.blocks[0].header, PROPERTY_CHANGE_HEADER) && + file.name === nextFile.name && + (file.isDeleted === true || file.isNew === true) ) { i += 1; } @@ -477,7 +478,6 @@ return ret; } - function getExtension(filename, language) { var nameSplit = filename.split('.'); if (nameSplit.length > 1) { @@ -487,7 +487,6 @@ return language; } - function getSrcFilename(line, cfg) { return _getFilename('---', line, cfg.srcPrefix); } @@ -513,7 +512,7 @@ var values = FilenameRegExp.exec(line); if (values && values[1]) { filename = values[1]; - var matchingPrefixes = prefixes.filter(function (p) { + var matchingPrefixes = prefixes.filter(function(p) { return filename.indexOf(p) === 0; }); @@ -532,6 +531,5 @@ } module.exports.DiffParser = new DiffParser(); -}) -(); +})(); From 5f0048ceaa8eb4a43533ba29c2f79940a0212314 Mon Sep 17 00:00:00 2001 From: Jinheng Zhu Date: Wed, 3 May 2017 16:28:26 +0800 Subject: [PATCH 4/8] fix some typo errs --- src/diff-parser.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/diff-parser.js b/src/diff-parser.js index 2d5a9b9..5b047e2 100644 --- a/src/diff-parser.js +++ b/src/diff-parser.js @@ -223,7 +223,7 @@ var svnNullFileMode = /^(.+)(\s+)(\(nonexistent\))$/; var svnWithVersionFileMode = /^(.+)(\s+)(\(revision\s+\d+\))$/; - /* if we use command `svn diff --git`. we wiil get header like that: + /* if we use command `svn diff --git`. we will get header like that: * * ``` * diff --git a/color_doc.docx b/color_doc.docx @@ -320,7 +320,6 @@ (values = getSrcFilename(line, config)) ) { checkSvnFileMode(values, true); - // currentFile.oldName = values; currentFile.language = getExtension(currentFile.oldName, currentFile.language); return; } From 1d5daa41386fb145227dd5f822960c70995abd87 Mon Sep 17 00:00:00 2001 From: Jinheng Zhu Date: Wed, 3 May 2017 17:00:22 +0800 Subject: [PATCH 5/8] 1. add test case. 2. fix typo error --- src/diff-parser.js | 4 ++-- test/diff-parser-tests.js | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/diff-parser.js b/src/diff-parser.js index 5b047e2..9052e46 100644 --- a/src/diff-parser.js +++ b/src/diff-parser.js @@ -455,7 +455,7 @@ * You proberly do not want to see the second record. So will provide an `ignoreSvnPropertyChange` option to do that for you. */ function dropSvnPropertyChangeFiles(files) { - const GIT_BINNARY_HEADER = 'GIT binary patch'; + const GIT_BINARY_HEADER = 'GIT binary patch'; const PROPERTY_CHANGE_HEADER = 'Property changes on:'; var ret = []; for (var i = 0; i < files.length - 1; i++) { @@ -464,7 +464,7 @@ ret.push(file); if (file.blocks.length > 0 && - utils.startsWith(file.blocks[0].header, GIT_BINNARY_HEADER) && + utils.startsWith(file.blocks[0].header, GIT_BINARY_HEADER) && nextFile.blocks.length > 0 && utils.startsWith(nextFile.blocks[0].header, PROPERTY_CHANGE_HEADER) && file.name === nextFile.name && diff --git a/test/diff-parser-tests.js b/test/diff-parser-tests.js index b910868..5dd444e 100644 --- a/test/diff-parser-tests.js +++ b/test/diff-parser-tests.js @@ -728,5 +728,45 @@ describe('DiffParser', function() { assert.deepEqual(linesContent, [' function foo() {', '-var bar = "Whoops!";', '+var baz = "Whoops!";', ' }', ' ']); }); + + it('should parse `svn diff --git` content', function() { + var diff = + 'Index: color_doc.docx\n' + + '===================================================================\n' + + 'diff --git a/color_doc.docx b/color_doc.docx\n' + + 'new file mode 10644\n' + + 'GIT binary patch\n' + + 'literal 296291\n' + + 'zc%1CHV|b>|mmvJaPteH|b!;ac+w9n8$F^;E+_5|E*jC3@$F^-JoBsW0W@mS2->>`O\n' + + ' \n' + + 'literal 0\n' + + 'Hc$@ Date: Thu, 4 May 2017 10:52:43 +0800 Subject: [PATCH 6/8] remove some useless comment lines --- src/diff-parser.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/diff-parser.js b/src/diff-parser.js index 9052e46..4a012c5 100644 --- a/src/diff-parser.js +++ b/src/diff-parser.js @@ -239,7 +239,6 @@ if (isOld) { if ((result = svnNullFileMode.exec(fileName))) { currentFile.oldName = result[1]; - // currentFile.isNew = true; } else if ((result = svnWithVersionFileMode.exec(fileName))) { currentFile.oldName = result[1]; } else { @@ -248,7 +247,6 @@ } else { if ((result = svnNullFileMode.exec(fileName))) { currentFile.newName = result[1]; - // currentFile.isDeleted = true; } else if ((result = svnWithVersionFileMode.exec(fileName))) { currentFile.newName = result[1]; } else { @@ -331,7 +329,6 @@ if (currentFile && !currentFile.newName && utils.startsWith(line, '+++ ') && (values = getDstFilename(line, config))) { checkSvnFileMode(values, false); - // currentFile.newName = values; currentFile.language = getExtension(currentFile.newName, currentFile.language); return; } From e0daceb1d35518aaba094a5f1e4501df19691b10 Mon Sep 17 00:00:00 2001 From: Jinheng Zhu Date: Fri, 5 May 2017 15:54:39 +0800 Subject: [PATCH 7/8] add more test cases --- test/diff-parser-tests.js | 188 +++++++++++++++++++++++++++----------- 1 file changed, 134 insertions(+), 54 deletions(-) diff --git a/test/diff-parser-tests.js b/test/diff-parser-tests.js index 5dd444e..3c6e912 100644 --- a/test/diff-parser-tests.js +++ b/test/diff-parser-tests.js @@ -5,8 +5,7 @@ var DiffParser = require('../src/diff-parser.js').DiffParser; describe('DiffParser', function() { describe('generateDiffJson', function() { it('should parse unix with \n diff', function() { - var diff = - 'diff --git a/sample b/sample\n' + + var diff = 'diff --git a/sample b/sample\n' + 'index 0000001..0ddf2ba\n' + '--- a/sample\n' + '+++ b/sample\n' + @@ -17,8 +16,7 @@ describe('DiffParser', function() { }); it('should parse windows with \r\n diff', function() { - var diff = - 'diff --git a/sample b/sample\r\n' + + var diff = 'diff --git a/sample b/sample\r\n' + 'index 0000001..0ddf2ba\r\n' + '--- a/sample\r\n' + '+++ b/sample\r\n' + @@ -29,8 +27,7 @@ describe('DiffParser', function() { }); it('should parse old os x with \r diff', function() { - var diff = - 'diff --git a/sample b/sample\r' + + var diff = 'diff --git a/sample b/sample\r' + 'index 0000001..0ddf2ba\r' + '--- a/sample\r' + '+++ b/sample\r' + @@ -41,8 +38,7 @@ describe('DiffParser', function() { }); it('should parse mixed eols diff', function() { - var diff = - 'diff --git a/sample b/sample\n' + + var diff = 'diff --git a/sample b/sample\n' + 'index 0000001..0ddf2ba\r\n' + '--- a/sample\r' + '+++ b/sample\r\n' + @@ -64,8 +60,7 @@ describe('DiffParser', function() { } it('should parse diff with special characters', function() { - var diff = - 'diff --git "a/bla with \ttab.scala" "b/bla with \ttab.scala"\n' + + var diff = 'diff --git "a/bla with \ttab.scala" "b/bla with \ttab.scala"\n' + 'index 4c679d7..e9bd385 100644\n' + '--- "a/bla with \ttab.scala"\n' + '+++ "b/bla with \ttab.scala"\n' + @@ -85,8 +80,7 @@ describe('DiffParser', function() { }); it('should parse diff with prefix', function() { - var diff = - 'diff --git "\tbla with \ttab.scala" "\tbla with \ttab.scala"\n' + + var diff = 'diff --git "\tbla with \ttab.scala" "\tbla with \ttab.scala"\n' + 'index 4c679d7..e9bd385 100644\n' + '--- "\tbla with \ttab.scala"\n' + '+++ "\tbla with \ttab.scala"\n' + @@ -95,7 +89,10 @@ describe('DiffParser', function() { '+cenas com ananas\n' + '+bananas'; - var result = DiffParser.generateDiffJson(diff, {'srcPrefix': '\t', 'dstPrefix': '\t'}); + var result = DiffParser.generateDiffJson(diff, { + 'srcPrefix': '\t', + 'dstPrefix': '\t' + }); var file1 = result[0]; assert.equal(1, result.length); assert.equal(2, file1.addedLines); @@ -106,8 +103,7 @@ describe('DiffParser', function() { }); it('should parse diff with deleted file', function() { - var diff = - 'diff --git a/src/var/strundefined.js b/src/var/strundefined.js\n' + + var diff = 'diff --git a/src/var/strundefined.js b/src/var/strundefined.js\n' + 'deleted file mode 100644\n' + 'index 04e16b0..0000000\n' + '--- a/src/var/strundefined.js\n' + @@ -133,8 +129,7 @@ describe('DiffParser', function() { }); it('should parse diff with new file', function() { - var diff = - 'diff --git a/test.js b/test.js\n' + + var diff = 'diff --git a/test.js b/test.js\n' + 'new file mode 100644\n' + 'index 0000000..e1e22ec\n' + '--- /dev/null\n' + @@ -163,8 +158,7 @@ describe('DiffParser', function() { }); it('should parse diff with nested diff', function() { - var diff = - 'diff --git a/src/offset.js b/src/offset.js\n' + + var diff = 'diff --git a/src/offset.js b/src/offset.js\n' + 'index cc6ffb4..fa51f18 100644\n' + '--- a/src/offset.js\n' + '+++ b/src/offset.js\n' + @@ -192,8 +186,7 @@ describe('DiffParser', function() { }); it('should parse diff with multiple blocks', function() { - var diff = - 'diff --git a/src/attributes/classes.js b/src/attributes/classes.js\n' + + var diff = 'diff --git a/src/attributes/classes.js b/src/attributes/classes.js\n' + 'index c617824..c8d1393 100644\n' + '--- a/src/attributes/classes.js\n' + '+++ b/src/attributes/classes.js\n' + @@ -236,8 +229,7 @@ describe('DiffParser', function() { }); it('should parse diff with multiple files', function() { - var diff = - 'diff --git a/src/core/init.js b/src/core/init.js\n' + + var diff = 'diff --git a/src/core/init.js b/src/core/init.js\n' + 'index e49196a..50f310c 100644\n' + '--- a/src/core/init.js\n' + '+++ b/src/core/init.js\n' + @@ -289,8 +281,7 @@ describe('DiffParser', function() { }); it('should parse combined diff', function() { - var diff = - 'diff --combined describe.c\n' + + var diff = 'diff --combined describe.c\n' + 'index fabadb8,cc95eb0..4866510\n' + '--- a/describe.c\n' + '+++ b/describe.c\n' + @@ -334,8 +325,7 @@ describe('DiffParser', function() { }); it('should parse diffs with copied files', function() { - var diff = - 'diff --git a/index.js b/more-index.js\n' + + var diff = 'diff --git a/index.js b/more-index.js\n' + 'dissimilarity index 5%\n' + 'copy from index.js\n' + 'copy to more-index.js\n'; @@ -354,8 +344,7 @@ describe('DiffParser', function() { }); it('should parse diffs with moved files', function() { - var diff = - 'diff --git a/more-index.js b/other-index.js\n' + + var diff = 'diff --git a/more-index.js b/other-index.js\n' + 'similarity index 86%\n' + 'rename from more-index.js\n' + 'rename to other-index.js\n'; @@ -374,8 +363,7 @@ describe('DiffParser', function() { }); it('should parse diffs correct line numbers', function() { - var diff = - 'diff --git a/sample b/sample\n' + + var diff = 'diff --git a/sample b/sample\n' + 'index 0000001..0ddf2ba\n' + '--- a/sample\n' + '+++ b/sample\n' + @@ -400,8 +388,7 @@ describe('DiffParser', function() { }); it('should parse unified non git diff and strip timestamps off the headers', function() { - var diff = - '--- a/sample.js 2016-10-25 11:37:14.000000000 +0200\n' + + var diff = '--- a/sample.js 2016-10-25 11:37:14.000000000 +0200\n' + '+++ b/sample.js 2016-10-25 11:37:14.000000000 +0200\n' + '@@ -1 +1,2 @@\n' + '-test\n' + @@ -424,8 +411,7 @@ describe('DiffParser', function() { }); it('should parse unified non git diff', function() { - var diff = - '--- a/sample.js\n' + + var diff = '--- a/sample.js\n' + '+++ b/sample.js\n' + '@@ -1 +1,2 @@\n' + '-test\n' + @@ -448,8 +434,7 @@ describe('DiffParser', function() { }); it('should parse unified diff with multiple hunks and files', function() { - var diff = - '--- sample.js\n' + + var diff = '--- sample.js\n' + '+++ sample.js\n' + '@@ -1 +1,2 @@\n' + '-test\n' + @@ -494,8 +479,7 @@ describe('DiffParser', function() { }); it('should parse diff with --- and +++ in the context lines', function() { - var diff = - '--- sample.js\n' + + var diff = '--- sample.js\n' + '+++ sample.js\n' + '@@ -1,8 +1,8 @@\n' + ' test\n' + @@ -525,8 +509,7 @@ describe('DiffParser', function() { }); it('should parse diff without proper hunk headers', function() { - var diff = - '--- sample.js\n' + + var diff = '--- sample.js\n' + '+++ sample.js\n' + '@@ @@\n' + ' test'; @@ -547,8 +530,7 @@ describe('DiffParser', function() { }); it('should parse binary file diff', function() { - var diff = - 'diff --git a/last-changes-config.png b/last-changes-config.png\n' + + 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' + @@ -567,8 +549,7 @@ describe('DiffParser', function() { }); it('should parse diff with --find-renames', function() { - var diff = - 'diff --git a/src/test-bar.js b/src/test-baz.js\n' + + var diff = 'diff --git a/src/test-bar.js b/src/test-baz.js\n' + 'similarity index 98%\n' + 'rename from src/test-bar.js\n' + 'rename to src/test-baz.js\n' + @@ -599,8 +580,7 @@ describe('DiffParser', function() { }); it('should parse diff with prefix', function() { - var diff = - 'diff --git "\tTest.scala" "\tScalaTest.scala"\n' + + var diff = 'diff --git "\tTest.scala" "\tScalaTest.scala"\n' + 'similarity index 88%\n' + 'rename from Test.scala\n' + 'rename to ScalaTest.scala\n' + @@ -642,7 +622,10 @@ describe('DiffParser', function() { ' }\n' + ' '; - var result = DiffParser.generateDiffJson(diff, {'srcPrefix': '\t', 'dstPrefix': '\t'}); + var result = DiffParser.generateDiffJson(diff, { + 'srcPrefix': '\t', + 'dstPrefix': '\t' + }); assert.equal(3, result.length); var file1 = result[0]; @@ -673,8 +656,7 @@ describe('DiffParser', function() { }); it('should parse binary with content', function() { - var diff = - 'diff --git a/favicon.png b/favicon.png\n' + + var diff = 'diff --git a/favicon.png b/favicon.png\n' + 'deleted file mode 100644\n' + 'index 2a9d516a5647205d7be510dd0dff93a3663eff6f..0000000000000000000000000000000000000000\n' + 'GIT binary patch\n' + @@ -729,9 +711,8 @@ describe('DiffParser', function() { [' function foo() {', '-var bar = "Whoops!";', '+var baz = "Whoops!";', ' }', ' ']); }); - it('should parse `svn diff --git` content', function() { - var diff = - 'Index: color_doc.docx\n' + + it('should ignore the property set record of `svn diff --git` with ignoreSvnPropertyChange = true', function() { + var diff = 'Index: color_doc.docx\n' + '===================================================================\n' + 'diff --git a/color_doc.docx b/color_doc.docx\n' + 'new file mode 10644\n' + @@ -759,7 +740,9 @@ describe('DiffParser', function() { '+application/octet-stream\n' + '\\ No newline at end of property\n' + ' '; - var result = DiffParser.generateDiffJson(diff, {ignoreSvnPropertyChange: true}); + var result = DiffParser.generateDiffJson(diff, { + ignoreSvnPropertyChange: true + }); assert.equal(1, result.length); var file1 = result[0]; @@ -768,5 +751,102 @@ describe('DiffParser', function() { assert.equal(true, file1.isNew); assert.equal('10644', file1.newFileMode); }); + + it('should parse `svn diff --git` content without ignoreSvnPropertyChange', function() { + var diff = 'Index: color_doc.docx\n' + + '===================================================================\n' + + 'diff --git a/color_doc.docx b/color_doc.docx\n' + + 'new file mode 10644\n' + + 'GIT binary patch\n' + + 'literal 296291\n' + + 'zc%1CHV|b>|mmvJaPteH|b!;ac+w9n8$F^;E+_5|E*jC3@$F^-JoBsW0W@mS2->>`O\n' + + ' \n' + + 'literal 0\n' + + 'Hc$@ Date: Fri, 5 May 2017 16:09:16 +0800 Subject: [PATCH 8/8] fix styles pros --- test/diff-parser-tests.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/diff-parser-tests.js b/test/diff-parser-tests.js index 3c6e912..7f77d8b 100644 --- a/test/diff-parser-tests.js +++ b/test/diff-parser-tests.js @@ -796,7 +796,6 @@ describe('DiffParser', function() { assert.equal('docx', file2.language); }); - it('should parse multiple files without ignoreSvnPropertyChange', function() { var diff = 'Index: trunk/README.md\n' + '===================================================================\n' + @@ -843,10 +842,9 @@ describe('DiffParser', function() { var file4 = result[3]; assert.equal('trunk/octofamily/momma_octocat.txt', file4.oldName); - assert.equal("/dev/null", file4.newName); + assert.equal('/dev/null', file4.newName); assert.equal(true, file4.isDeleted); assert.equal(true, file4.isGitDiff); - }); }); });