fix: pass merge commit messages to git via stdin (#39269)

`git commit --message=` passes the merge message as a single argument,
which Linux caps at 128 KiB and Windows at 32 KiB for the whole command
line. Long messages failed with `argument list too long` and the merge
box toast showed the raw HTML 500 page.

Pass the message via `--file=-` on stdin instead, and answer
fetch-action requests with JSON on server errors so the toast shows the
error text. Limits merge commit messages to 512KB which could be
extended or made configurable later.

Fixes: https://github.com/go-gitea/gitea/issues/39261
Fixes: https://github.com/go-gitea/gitea/issues/30276
Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwind
2026-09-19 15:04:53 +02:00
committed by GitHub
parent cc34c26172
commit cdf786ce92
21 changed files with 175 additions and 93 deletions
+11
View File
@@ -248,3 +248,14 @@ func GetFullCommitID(ctx context.Context, repo RepositoryFacade, shortID string)
}
return strings.TrimSpace(commitID), nil
}
func AddObjectMessageArgument(cmd *gitcmd.Command, typ ObjectType, message string) error {
if len(message) > 512*1024 {
// It doesn't make sense to store very large messages in git objects,
// and it never succeeded in the past due to the command line argument limit (e.g.: 128K on Linux).
// If any real world user would complain about the limit, let them explain why, then make the limit configurable.
return util.NewInvalidArgumentErrorf("git %s message is too long", typ)
}
cmd.AddArguments("--file=-").WithStdinBytes([]byte(message))
return nil
}