Skip to content
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
15 changes: 11 additions & 4 deletions gitdiff/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ func (p *parser) ParseBinaryFragments(f *File) (n int, err error) {
}

func (p *parser) ParseBinaryMarker() (isBinary bool, hasData bool, err error) {
switch p.Line(0) {
case "GIT binary patch\n":
line := p.Line(0)
switch {
case line == "GIT binary patch\n":
hasData = true
case "Binary files differ\n":
case "Files differ\n":
case isBinaryNoDataMarker(line):
default:
return false, false, nil
}
Expand All @@ -65,6 +65,13 @@ func (p *parser) ParseBinaryMarker() (isBinary bool, hasData bool, err error) {
return true, hasData, nil
}

func isBinaryNoDataMarker(line string) bool {
if strings.HasSuffix(line, " differ\n") {
return strings.HasPrefix(line, "Binary files ") || strings.HasPrefix(line, "Files ")
}
return false
}

func (p *parser) ParseBinaryFragmentHeader() (*BinaryFragment, error) {
parts := strings.SplitN(strings.TrimSuffix(p.Line(0), "\n"), " ", 2)
if len(parts) < 2 {
Expand Down
10 changes: 10 additions & 0 deletions gitdiff/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ func TestParseBinaryMarker(t *testing.T) {
IsBinary: true,
HasData: false,
},
"binaryFileNoPatchPaths": {
Input: "Binary files a/foo.bin and b/foo.bin differ\n",
IsBinary: true,
HasData: false,
},
"fileNoPatch": {
Input: "Files differ\n",
IsBinary: true,
HasData: false,
},
"textFile": {
Input: "@@ -10,14 +22,31 @@\n",
IsBinary: false,
Expand Down
Loading