Skip to content

Support renamed binary files without index-row #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,22 @@ func TestParseFileDiffHeaders(t *testing.T) {
},
},
},
{
filename: "sample_file_extended_binary_rename_no_index.diff",
wantDiff: &FileDiff{
OrigName: "a/data/foo.txt",
OrigTime: nil,
NewName: "b/data/bar.txt",
NewTime: nil,
Extended: []string{
"diff --git a/data/foo.txt b/data/bar.txt",
"similarity index 100%",
"rename from data/foo.txt",
"rename to data/bar.txt",
"Binary files a/data/foo.txt and b/data/bar.txt differ",
},
},
},
}
for _, test := range tests {
t.Run(test.filename, func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions diff/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ func handleEmpty(fd *FileDiff) (wasEmpty bool) {
(lineCount == 6 && linesHavePrefixes(1, "old mode ", 2, "new mode ") && linesHavePrefixes(4, "copy from ", 5, "copy to "))

isRename := (lineCount == 4 && linesHavePrefixes(2, "rename from ", 3, "rename to ")) ||
(lineCount == 5 && linesHavePrefixes(2, "rename from ", 3, "rename to ") && lineHasPrefix(4, "Binary files ")) ||
(lineCount == 6 && linesHavePrefixes(2, "rename from ", 3, "rename to ") && lineHasPrefix(5, "Binary files ")) ||
(lineCount == 6 && linesHavePrefixes(1, "old mode ", 2, "new mode ") && linesHavePrefixes(4, "rename from ", 5, "rename to "))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
diff --git a/data/foo.txt b/data/bar.txt
similarity index 100%
rename from data/foo.txt
rename to data/bar.txt
Binary files a/data/foo.txt and b/data/bar.txt differ