Skip to content

Commit 9001611

Browse files
committed
diff: support renamed, updated binary file
This commit parses a diff with a renamed, updated binary file and adds a test case for it.
1 parent 3637c60 commit 9001611

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

diff/diff_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,23 @@ func TestParseFileDiffHeaders(t *testing.T) {
203203
},
204204
},
205205
},
206+
{
207+
filename: "sample_file_extended_binary_rename.diff",
208+
wantDiff: &FileDiff{
209+
OrigName: "a/data/Font.png",
210+
OrigTime: nil,
211+
NewName: "b/data/Other.png",
212+
NewTime: nil,
213+
Extended: []string{
214+
"diff --git a/data/Font.png b/data/Other.png",
215+
"similarity index 51%",
216+
"rename from data/Font.png",
217+
"rename to data/Other.png",
218+
"index 17a971d..599f8dd 100644",
219+
"Binary files a/data/Font.png and b/data/Other.png differ",
220+
},
221+
},
222+
},
206223
}
207224
for _, test := range tests {
208225
diffData, err := ioutil.ReadFile(filepath.Join("testdata", test.filename))

diff/parse.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@ func handleEmpty(fd *FileDiff) (wasEmpty bool) {
349349
fd.OrigName = names[0]
350350
fd.NewName = names[1]
351351
return true
352+
case len(fd.Extended) == 6 && strings.HasPrefix(fd.Extended[5], "Binary files ") && strings.HasPrefix(fd.Extended[0], "diff --git "):
353+
names := strings.SplitN(fd.Extended[0][len("diff --git "):], " ", 2)
354+
fd.OrigName = names[0]
355+
fd.NewName = names[1]
356+
return true
352357
case len(fd.Extended) == 3 && strings.HasPrefix(fd.Extended[2], "Binary files ") && strings.HasPrefix(fd.Extended[0], "diff --git "):
353358
names := strings.SplitN(fd.Extended[0][len("diff --git "):], " ", 2)
354359
fd.OrigName = names[0]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
diff --git a/data/Font.png b/data/Other.png
2+
similarity index 51%
3+
rename from data/Font.png
4+
rename to data/Other.png
5+
index 17a971d..599f8dd 100644
6+
Binary files a/data/Font.png and b/data/Other.png differ

0 commit comments

Comments
 (0)