feat: return error when commit is empty

main
sudo pacman -Syu 2021-05-11 04:57:25 +00:00 committed by GitHub
parent 4298794c82
commit 31b2d1f446
2 changed files with 8 additions and 3 deletions

View File

@ -60,6 +60,10 @@ func TestNewCommit(t *testing.T) {
},
},
},
{
name: "Empty commit",
wantErr: ErrEmptyCommit,
},
}
for _, tc := range tests {

View File

@ -20,12 +20,13 @@ type OptionFn func(*Commit) error
func GetRawHeader(gitCommit git.Commit) OptionFn {
return func(c *Commit) error {
message := strings.TrimSpace(gitCommit.Message)
messages := strings.Split(message, "\n")
if len(messages) == 0 {
if gitCommit.Message == "" {
return ErrEmptyCommit
}
message := strings.TrimSpace(gitCommit.Message)
messages := strings.Split(message, "\n")
c.RawHeader = messages[0]
return nil