mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Tolerate trailing newlines in AddCoAuthorToDescription
Callers currently hand this function a trimmed description, so the output is always clean. An upcoming change to the commit-panel getters will stop trimming at the callsite (so that whitespace typed by the user round-trips through the preservation file exactly), at which point the description can end with one or more newlines. Without this change, a user who presses Enter after their description body and then invokes "Add co-author" would end up with two blank lines between the body and the trailer instead of the expected one.
This commit is contained in:
parent
58309b02a9
commit
4ab36461cb
|
|
@ -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:") {
|
||||
|
|
|
|||
|
|
@ -483,6 +483,11 @@ func TestAddCoAuthorToDescription(t *testing.T) {
|
|||
description: "Body\n\nCo-authored-by: Jane Smith <jane@smith.com>",
|
||||
expectedResult: "Body\n\nCo-authored-by: Jane Smith <jane@smith.com>\nCo-authored-by: John Doe <john@doe.com>",
|
||||
},
|
||||
{
|
||||
name: "Description with trailing newlines",
|
||||
description: "Body\n\n",
|
||||
expectedResult: "Body\n\nCo-authored-by: John Doe <john@doe.com>",
|
||||
},
|
||||
}
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue