Skip to content

Commit

Permalink
Fix binary headers in formatted patches
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bluekeyes committed Jan 8, 2025
1 parent 14da3d3 commit cba925d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gitdiff/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ func (fm *formatter) FormatFile(f *File) {

if f.IsBinary {
if f.BinaryFragment == nil {
fm.WriteString("Binary files fmer\n")
fm.WriteString("Binary files ")
fm.WriteQuotedName("a/" + aName)
fm.WriteString(" and ")
fm.WriteQuotedName("b/" + bName)
fm.WriteString(" differ\n")
} else {
fm.WriteString("GIT binary patch\n")
fm.FormatBinaryFragment(f.BinaryFragment)
Expand Down
1 change: 1 addition & 0 deletions gitdiff/format_roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestFormatRoundtrip(t *testing.T) {
// data is slightly different when re-encoded by Go.
{File: "binary_modify.patch", SkipTextCompare: true},
{File: "binary_new.patch", SkipTextCompare: true},
{File: "binary_modify_nodata.patch"},
}

for _, patch := range patches {
Expand Down
3 changes: 3 additions & 0 deletions gitdiff/testdata/string/binary_modify_nodata.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
diff --git a/file.bin b/file.bin
index a7f4d5d..bdc9a70 100644
Binary files a/file.bin and b/file.bin differ

0 comments on commit cba925d

Please sign in to comment.