diff --git a/modules/git/commit_message.go b/modules/git/commit_message.go index 8fd3601f0d0..e300a7f857a 100644 --- a/modules/git/commit_message.go +++ b/modules/git/commit_message.go @@ -70,7 +70,7 @@ func (c *CommitMessage) MessageTrailer() CommitMessageTrailerValues { var commitMessageTrailerSplit = sync.OnceValue(func() *regexp.Regexp { // the sep is either something like "\n---\n" or "\n\n" in the body, or at the start of the body like "---\n" - return regexp.MustCompile(`(?s)^(?P.*?)(?P^|^\n|^-{3,}\n|\n-{3,}\n|\n\n)(?P(?:[A-Za-z0-9][-A-Za-z0-9]*:[^\n]*\n?)*)$`) + return regexp.MustCompile(`(?s)^(?P.*?)(?P^|^\n|^-{3,}\n|\n-{3,}\n|\n\n)(?P(?:[A-Za-z0-9][-A-Za-z0-9]*:[^\n]*\n?)*\n*)$`) }) func CommitMessageSplitTrailer(s string) (content, sep, trailer string) { diff --git a/modules/git/commit_message_test.go b/modules/git/commit_message_test.go index 049f1c03f78..f5893447004 100644 --- a/modules/git/commit_message_test.go +++ b/modules/git/commit_message_test.go @@ -26,6 +26,7 @@ func TestCommitMessageTrailer(t *testing.T) { {"a", "a", "", ""}, {"a\n\nk", "a\n\nk", "", ""}, {"a\n\nk:v", "a", "\n\n", "k:v"}, + {"a\n\nk:v\n\n", "a", "\n\n", "k:v\n\n"}, {"a\n--\nk:v", "a\n--\nk:v", "", ""}, {"a\n---\nk:v", "a", "\n---\n", "k:v"}, diff --git a/services/pull/pull_test.go b/services/pull/pull_test.go index 7b26f1ebaae..71f5aa156e9 100644 --- a/services/pull/pull_test.go +++ b/services/pull/pull_test.go @@ -44,13 +44,7 @@ func TestPullRequest_FormatSquashMergeCommitMessages(t *testing.T) { defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultMergeMessageSize, 0)() - // all commits - assert.Equal(t, "* commit msg 1\n\n* commit msg 2\n\nCommit description.\n\n", - formatSquashMergeCommitMessages([]*git.Commit{newest, oldest})) - - // PR-description mode: pass all-but-oldest so the oldest is not duplicated - assert.Equal(t, "* commit msg 2\n\nCommit description.\n\n", - formatSquashMergeCommitMessages([]*git.Commit{newest})) + assert.Equal(t, "* commit msg 1\n\n* commit msg 2\n\nCommit description.\n\n", formatSquashMergeCommitMessages([]*git.Commit{newest, oldest})) utf8Msg := &git.Commit{CommitMessage: git.CommitMessage{MessageRaw: "🌞"}} setting.Repository.PullRequest.DefaultMergeMessageSize = 3 @@ -127,6 +121,7 @@ func TestBuildSquashMergeCommitMessages(t *testing.T) { {"title", []string{"the-user"}, "title\n---------\nCo-authored-by: the-user\n"}, {"title\n\nKey: val", []string{"the-user"}, "title\n\nKey: val\nCo-authored-by: the-user\n"}, {"title\n\n----\nKey: val", []string{"the-user"}, "title\n\n----\nKey: val\nCo-authored-by: the-user\n"}, + {"title\n\n----\nKey: val\n\n", []string{"the-user"}, "title\n\n----\nKey: val\nCo-authored-by: the-user\n"}, {"title\n\nbody", nil, "title\n\nbody"}, {"title\n\nbody", []string{"the-user"}, "title\n\nbody\n---------\nCo-authored-by: the-user\n"},