diff --git a/src/parser/diff/ArcanistDiffParser.php b/src/parser/diff/ArcanistDiffParser.php index a31fc980..1a7d478d 100644 --- a/src/parser/diff/ArcanistDiffParser.php +++ b/src/parser/diff/ArcanistDiffParser.php @@ -620,6 +620,19 @@ class ArcanistDiffParser { return; } + // This occurs under "hg diff --git" when a binary file is removed. See + // test case "hg-binary-delete.hgdiff". (I believe it never occurs under + // git, which reports the "files X and /dev/null differ" string above. Git + // can not apply these patches.) + $is_hg_binary_delete = preg_match( + '/^Binary file .* has changed$/', + $line); + if ($is_hg_binary_delete) { + $this->nextNonemptyLine(); + $this->markBinary($change); + return; + } + // With "git diff --binary" (not a normal mode, but one users may explicitly // invoke and then, e.g., copy-paste into the web console) or "hg diff // --git" (normal under hg workflows), we may encounter a literal binary diff --git a/src/parser/diff/__tests__/ArcanistDiffParserTestCase.php b/src/parser/diff/__tests__/ArcanistDiffParserTestCase.php index d7cd8fba..3bac9f98 100644 --- a/src/parser/diff/__tests__/ArcanistDiffParserTestCase.php +++ b/src/parser/diff/__tests__/ArcanistDiffParserTestCase.php @@ -488,6 +488,16 @@ EOTEXT ArcanistDiffChangeType::FILE_BINARY, $change->getFileType()); break; + case 'hg-binary-delete.hgdiff': + $this->assertEqual(1, count($changes)); + $change = reset($changes); + $this->assertEqual( + ArcanistDiffChangeType::TYPE_DELETE, + $change->getType()); + $this->assertEqual( + ArcanistDiffChangeType::FILE_BINARY, + $change->getFileType()); + break; case 'git-replace-symlink.gitdiff': $this->assertEqual(1, count($changes)); $change = array_shift($changes); diff --git a/src/parser/diff/__tests__/data/hg-binary-delete.hgdiff b/src/parser/diff/__tests__/data/hg-binary-delete.hgdiff new file mode 100644 index 00000000..6d01163c --- /dev/null +++ b/src/parser/diff/__tests__/data/hg-binary-delete.hgdiff @@ -0,0 +1,3 @@ +diff --git a/binary.png b/binary.png +deleted file mode 100755 +Binary file binary.png has changed