Skip to content

Commit fffa3cc

Browse files
authored
Fix binary headers in formatted patches (#56)
Include file names in the header (now that we can actually parse them) and fix a bad find-and-replace that changed "differ" to "fmer". Add a new test to verify that binary files without data format correctly.
1 parent 14da3d3 commit fffa3cc

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

gitdiff/format.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ func (fm *formatter) FormatFile(f *File) {
169169

170170
if f.IsBinary {
171171
if f.BinaryFragment == nil {
172-
fm.WriteString("Binary files fmer\n")
172+
fm.WriteString("Binary files ")
173+
fm.WriteQuotedName("a/" + aName)
174+
fm.WriteString(" and ")
175+
fm.WriteQuotedName("b/" + bName)
176+
fm.WriteString(" differ\n")
173177
} else {
174178
fm.WriteString("GIT binary patch\n")
175179
fm.FormatBinaryFragment(f.BinaryFragment)

gitdiff/format_roundtrip_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestFormatRoundtrip(t *testing.T) {
3131
// data is slightly different when re-encoded by Go.
3232
{File: "binary_modify.patch", SkipTextCompare: true},
3333
{File: "binary_new.patch", SkipTextCompare: true},
34+
{File: "binary_modify_nodata.patch"},
3435
}
3536

3637
for _, patch := range patches {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
diff --git a/file.bin b/file.bin
2+
index a7f4d5d..bdc9a70 100644
3+
Binary files a/file.bin and b/file.bin differ

0 commit comments

Comments
 (0)