Fix duplicate co-author in squashed merge commit messages (#33020)

Fix: #31980

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
(cherry picked from commit a87168869a4ceffb2a3d84986640da357b0793cf)
This commit is contained in:
hiifong 2024-12-31 03:03:21 +08:00 committed by Earl Warren
parent 9b2f38261b
commit af91f4e203
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -5,6 +5,7 @@ package pull
import ( import (
"fmt" "fmt"
"strings"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
@ -66,7 +67,10 @@ func doMergeStyleSquash(ctx *mergeContext, message string) error {
if setting.Repository.PullRequest.AddCoCommitterTrailers && ctx.committer.String() != sig.String() { if setting.Repository.PullRequest.AddCoCommitterTrailers && ctx.committer.String() != sig.String() {
// add trailer // add trailer
message += fmt.Sprintf("\nCo-authored-by: %s\nCo-committed-by: %s\n", sig.String(), sig.String()) if !strings.Contains(message, fmt.Sprintf("Co-authored-by: %s", sig.String())) {
message += fmt.Sprintf("\nCo-authored-by: %s", sig.String())
}
message += fmt.Sprintf("\nCo-committed-by: %s\n", sig.String())
} }
cmdCommit := git.NewCommand(ctx, "commit"). cmdCommit := git.NewCommand(ctx, "commit").
AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email). AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email).