diff --git a/diff/diff_test.go b/diff/diff_test.go index ea4d1f1..d98da96 100644 --- a/diff/diff_test.go +++ b/diff/diff_test.go @@ -630,6 +630,25 @@ func TestParseMultiFileDiffHeaders(t *testing.T) { }, }, }, + { + filename: "sample_multi_file_without_extended.diff", + wantDiffs: []*FileDiff{ + { + OrigName: "source_1_a/file_1.txt", + OrigTime: nil, + NewName: "source_1_c/file_1.txt", + NewTime: nil, + Extended: nil, + }, + { + OrigName: "source_1_a/file_2.txt", + OrigTime: nil, + NewName: "source_1_c/file_2.txt", + NewTime: nil, + Extended: nil, + }, + }, + }, } for _, test := range tests { diffData, err := ioutil.ReadFile(filepath.Join("testdata", test.filename)) diff --git a/diff/parse.go b/diff/parse.go index 6f8ef08..ac23f42 100644 --- a/diff/parse.go +++ b/diff/parse.go @@ -308,7 +308,7 @@ func (r *FileDiffReader) readOneFileHeader(prefix []byte) (filename string, time type OverflowError string func (e OverflowError) Error() string { - return fmt.Sprintf("overflowed into next file: %s", e) + return fmt.Sprintf("overflowed into next file: %s", string(e)) } // ReadExtendedHeaders reads the extended header lines, if any, from a @@ -531,7 +531,7 @@ func (r *HunksReader) ReadHunk() (*Hunk, error) { return r.hunk, nil } - if len(line) >= 1 && !linePrefix(line[0]) { + if len(line) >= 1 && (!linePrefix(line[0]) || bytes.HasPrefix(line, []byte("--- "))) { // Bad hunk header line. If we're reading a multi-file // diff, this may be the end of the current // file. Return a "rich" error that lets our caller diff --git a/diff/testdata/sample_multi_file_without_extended.diff b/diff/testdata/sample_multi_file_without_extended.diff new file mode 100644 index 0000000..2669c36 --- /dev/null +++ b/diff/testdata/sample_multi_file_without_extended.diff @@ -0,0 +1,31 @@ +--- source_1_a/file_1.txt ++++ source_1_c/file_1.txt +@@ -1,11 +1,13 @@ + Text generated by www.randomtextgenerator.com + ++ + In to am attended desirous raptures declared diverted confined at. ++In to are desirous declared diverted confined at. ++In to am attended raptures declared diverted confined at. ++In to am attended desirous confined at. + Collected instantly remaining up certainly to necessary as. + Over walk dull into son boy door went new. + At or happiness commanded daughters as. + Is handsome an declared at received in extended vicinity subjects. +-Is handsome received in extended vicinity subjects. +-Is handsome an declared at vicinity subjects. + Into miss on he over been late pain an. + Only week bore boy what fat case left use. +--- source_1_a/file_2.txt ++++ source_1_c/file_2.txt +@@ -4,8 +4,8 @@ + Still round match we to. + Frankness pronounce daughters remainder extensive has but. ++Happiness cordially one determine concluded fat. + Plenty season beyond by hardly giving of. +-Consulted or acuteness dejection an smallness if. +-Outward general passage another as it. + Very his are come man walk one next. + Delighted prevailed supported too not remainder perpetual who furnished. + Nay affronting bed projection compliment instrument. ++Still round match we to here.