Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return preamble when a patch has no files #46

Merged
merged 1 commit into from
Jul 15, 2024
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
2 changes: 1 addition & 1 deletion gitdiff/file_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (p *parser) ParseNextFileHeader() (*File, string, error) {
return nil, "", err
}
}
return nil, "", nil
return nil, preamble.String(), nil
}

func (p *parser) ParseGitFileHeader() (*File, error) {
Expand Down
6 changes: 3 additions & 3 deletions gitdiff/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func Parse(r io.Reader) ([]*File, string, error) {
if err != nil {
return files, preamble, err
}
if len(files) == 0 {
preamble = pre
}
if file == nil {
break
}
Expand All @@ -50,9 +53,6 @@ func Parse(r io.Reader) ([]*File, string, error) {
}
}

if len(files) == 0 {
preamble = pre
}
files = append(files, file)
}

Expand Down
18 changes: 16 additions & 2 deletions gitdiff/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,24 @@ this is another line
--- could this be a header?
nope, it's just some dashes
`,
Output: nil,
Preamble: "",
Output: nil,
Preamble: `
this is a line
this is another line
--- could this be a header?
nope, it's just some dashes
`,
},
"detatchedFragmentLike": {
Input: `
a wild fragment appears?
@@ -1,3 +1,4 ~1,5 @@
`,
Output: nil,
Preamble: `
a wild fragment appears?
@@ -1,3 +1,4 ~1,5 @@
`,
},
"detatchedFragment": {
Input: `
Expand Down Expand Up @@ -426,6 +435,11 @@ Date: Tue Apr 2 22:55:40 2019 -0700
},
Preamble: textPreamble,
},
"noFiles": {
InputFile: "testdata/no_files.patch",
Output: nil,
Preamble: textPreamble,
},
"newBinaryFile": {
InputFile: "testdata/new_binary_file.patch",
Output: []*File{
Expand Down
8 changes: 8 additions & 0 deletions gitdiff/testdata/no_files.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
commit 5d9790fec7d95aa223f3d20936340bf55ff3dcbe
Author: Morton Haypenny <mhaypenny@example.com>
Date: Tue Apr 2 22:55:40 2019 -0700

A file with multiple fragments.

The content is arbitrary.

Loading