From a506dcf2791ddc1065b3329a0d0982493e509462 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Mon, 11 Mar 2019 11:49:53 -0700 Subject: [PATCH] fix: support binary rename patches example from the wild: https://chromium.googlesource.com/chromium/src/+/22b5144060f40e96f2e7faba8d5c15a288f6d0f7%5E%21/ --- src/diff.pegjs | 2 +- test/diff.test.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/diff.pegjs b/src/diff.pegjs index e6194ab..68a0154 100644 --- a/src/diff.pegjs +++ b/src/diff.pegjs @@ -85,7 +85,7 @@ binary_merge_conflict_diff rename_or_copy_diff = rename_or_copy_diff_header_line modes:changed_file_modes? similarity:similarity_index copy_from:rename_copy_from copy_to:rename_copy_to - index_modes:index_line? patch:patch? + index_modes:index_line? patch:(binary_declaration / patch)? { return postProcessSimilarityDiff(copy_from.operation, similarity, copy_from.file, copy_to.file, modes || index_modes, patch) } diff --git a/test/diff.test.js b/test/diff.test.js index a8a847f..ac95afe 100644 --- a/test/diff.test.js +++ b/test/diff.test.js @@ -521,6 +521,28 @@ exports.testBinaryFiles = function(test) { test.done() } +exports.testBinaryFilesRename = function(test) { + var str = dedent` + diff --git a/dir_a/one.png b/dir_b/one.png + similarity index 100% + rename from dir_a/one.png + rename to dir_b/one.png + Binary files differ + ` + + const output = diff.parse(str) + assert.deepEqual(output, [ + { + oldPath: 'dir_a/one.png', + newPath: 'dir_b/one.png', + hunks: undefined, + status: 'renamed', + similarity: 100 + } + ]) + test.done() +} + exports.testNoPatch = function(test) { var str = dedent` diff --git file.txt file.txt