Skip to content

diff: support renamed, updated binary file #38

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
Aug 19, 2020
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
17 changes: 17 additions & 0 deletions diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,23 @@ func TestParseFileDiffHeaders(t *testing.T) {
},
},
},
{
filename: "sample_file_extended_binary_rename.diff",
wantDiff: &FileDiff{
OrigName: "a/data/Font.png",
OrigTime: nil,
NewName: "b/data/Other.png",
NewTime: nil,
Extended: []string{
"diff --git a/data/Font.png b/data/Other.png",
"similarity index 51%",
"rename from data/Font.png",
"rename to data/Other.png",
"index 17a971d..599f8dd 100644",
"Binary files a/data/Font.png and b/data/Other.png differ",
},
},
},
}
for _, test := range tests {
diffData, err := ioutil.ReadFile(filepath.Join("testdata", test.filename))
Expand Down
5 changes: 5 additions & 0 deletions diff/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ func handleEmpty(fd *FileDiff) (wasEmpty bool) {
fd.NewName = names[1]
}
return true
case lineCount == 6 && strings.HasPrefix(fd.Extended[5], "Binary files ") && strings.HasPrefix(fd.Extended[2], "rename from ") && strings.HasPrefix(fd.Extended[3], "rename to "):
names := strings.SplitN(fd.Extended[0][len("diff --git "):], " ", 2)
fd.OrigName = names[0]
fd.NewName = names[1]
return true
case lineCount == 3 && strings.HasPrefix(fd.Extended[2], "Binary files ") || lineCount > 3 && strings.HasPrefix(fd.Extended[2], "GIT binary patch"):
names := strings.SplitN(fd.Extended[0][len("diff --git "):], " ", 2)
fd.OrigName, err = strconv.Unquote(names[0])
Expand Down
6 changes: 6 additions & 0 deletions diff/testdata/sample_file_extended_binary_rename.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
diff --git a/data/Font.png b/data/Other.png
similarity index 51%
rename from data/Font.png
rename to data/Other.png
index 17a971d..599f8dd 100644
Binary files a/data/Font.png and b/data/Other.png differ