@@ -80,7 +80,7 @@ func (r *MultiFileDiffReader) ReadFile() (*FileDiff, error) {
80
80
// need to perform the check here.
81
81
hr := fr .HunksReader ()
82
82
line , err := readLine (r .reader )
83
- if err != nil {
83
+ if err != nil && err != io . EOF {
84
84
return fd , err
85
85
}
86
86
line = bytes .TrimSuffix (line , []byte {'\n' })
@@ -340,9 +340,13 @@ func (r *FileDiffReader) ReadExtendedHeaders() ([]string, error) {
340
340
// that follow. It updates fd fields from the parsed extended headers.
341
341
func handleEmpty (fd * FileDiff ) (wasEmpty bool ) {
342
342
var err error
343
+ lineCount := len (fd .Extended )
344
+ if lineCount > 0 && ! strings .HasPrefix (fd .Extended [0 ], "diff --git " ) {
345
+ return false
346
+ }
343
347
switch {
344
- case (len ( fd . Extended ) == 3 || len (fd .Extended ) == 4 && strings .HasPrefix (fd .Extended [3 ], "Binary files " )) &&
345
- strings .HasPrefix (fd .Extended [1 ], "new file mode " ) && strings . HasPrefix ( fd . Extended [ 0 ], "diff --git " ) :
348
+ case (lineCount == 3 || lineCount == 4 && strings . HasPrefix (fd .Extended [ 3 ], "Binary files " ) || lineCount > 4 && strings .HasPrefix (fd .Extended [3 ], "GIT binary patch " )) &&
349
+ strings .HasPrefix (fd .Extended [1 ], "new file mode " ):
346
350
347
351
names := strings .SplitN (fd .Extended [0 ][len ("diff --git " ):], " " , 2 )
348
352
fd .OrigName = "/dev/null"
@@ -351,8 +355,8 @@ func handleEmpty(fd *FileDiff) (wasEmpty bool) {
351
355
fd .NewName = names [1 ]
352
356
}
353
357
return true
354
- case (len ( fd . Extended ) == 3 || len (fd .Extended ) == 4 && strings .HasPrefix (fd .Extended [3 ], "Binary files " )) &&
355
- strings .HasPrefix (fd .Extended [1 ], "deleted file mode " ) && strings . HasPrefix ( fd . Extended [ 0 ], "diff --git " ) :
358
+ case (lineCount == 3 || lineCount == 4 && strings . HasPrefix (fd .Extended [ 3 ], "Binary files " ) || lineCount > 4 && strings .HasPrefix (fd .Extended [3 ], "GIT binary patch " )) &&
359
+ strings .HasPrefix (fd .Extended [1 ], "deleted file mode " ):
356
360
357
361
names := strings .SplitN (fd .Extended [0 ][len ("diff --git " ):], " " , 2 )
358
362
fd .OrigName , err = strconv .Unquote (names [0 ])
@@ -361,7 +365,7 @@ func handleEmpty(fd *FileDiff) (wasEmpty bool) {
361
365
}
362
366
fd .NewName = "/dev/null"
363
367
return true
364
- case len ( fd . Extended ) == 4 && strings .HasPrefix (fd .Extended [2 ], "rename from " ) && strings .HasPrefix (fd .Extended [3 ], "rename to " ) && strings . HasPrefix ( fd . Extended [ 0 ], "diff --git " ):
368
+ case lineCount == 4 && strings .HasPrefix (fd .Extended [2 ], "rename from " ) && strings .HasPrefix (fd .Extended [3 ], "rename to " ):
365
369
names := strings .SplitN (fd .Extended [0 ][len ("diff --git " ):], " " , 2 )
366
370
fd .OrigName , err = strconv .Unquote (names [0 ])
367
371
if err != nil {
@@ -372,7 +376,7 @@ func handleEmpty(fd *FileDiff) (wasEmpty bool) {
372
376
fd .NewName = names [1 ]
373
377
}
374
378
return true
375
- case len ( fd . Extended ) == 3 && strings .HasPrefix (fd .Extended [2 ], "Binary files " ) && strings .HasPrefix (fd .Extended [0 ], "diff --git " ):
379
+ case lineCount == 3 && strings .HasPrefix (fd .Extended [2 ], "Binary files " ) || lineCount > 3 && strings .HasPrefix (fd .Extended [2 ], "GIT binary patch " ):
376
380
names := strings .SplitN (fd .Extended [0 ][len ("diff --git " ):], " " , 2 )
377
381
fd .OrigName , err = strconv .Unquote (names [0 ])
378
382
if err != nil {
0 commit comments