diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index 40d2b7319..6abf272b3 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -61,6 +61,7 @@ func AddCoAuthorToMessage(message string, author string) string { } func AddCoAuthorToDescription(description string, author string) string { + description = strings.TrimRight(description, "\n") if description != "" { lines := strings.Split(description, "\n") if strings.HasPrefix(lines[len(lines)-1], "Co-authored-by:") { diff --git a/pkg/commands/git_commands/commit_test.go b/pkg/commands/git_commands/commit_test.go index 6ea914c64..25966c06f 100644 --- a/pkg/commands/git_commands/commit_test.go +++ b/pkg/commands/git_commands/commit_test.go @@ -483,6 +483,11 @@ func TestAddCoAuthorToDescription(t *testing.T) { description: "Body\n\nCo-authored-by: Jane Smith ", expectedResult: "Body\n\nCo-authored-by: Jane Smith \nCo-authored-by: John Doe ", }, + { + name: "Description with trailing newlines", + description: "Body\n\n", + expectedResult: "Body\n\nCo-authored-by: John Doe ", + }, } for _, s := range scenarios { t.Run(s.name, func(t *testing.T) {