mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-21 20:23:41 +09:00
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:
@@ -51,6 +51,7 @@ type MergeOptions struct {
|
||||
Style repo_model.MergeStyle
|
||||
HeadCommitID string
|
||||
DeleteBranch bool
|
||||
Message string
|
||||
}
|
||||
|
||||
func testPullMerge(t *testing.T, session *TestSession, user, repo, pullNum string, mergeOptions MergeOptions) *httptest.ResponseRecorder {
|
||||
@@ -58,6 +59,7 @@ func testPullMerge(t *testing.T, session *TestSession, user, repo, pullNum strin
|
||||
"do": string(mergeOptions.Style),
|
||||
"head_commit_id": mergeOptions.HeadCommitID,
|
||||
"delete_branch_after_merge": util.Iif(mergeOptions.DeleteBranch, "on", ""),
|
||||
"merge_message_field": mergeOptions.Message,
|
||||
}
|
||||
var resp *httptest.ResponseRecorder
|
||||
require.Eventually(t, func() bool {
|
||||
@@ -77,6 +79,15 @@ func testPullMerge(t *testing.T, session *TestSession, user, repo, pullNum strin
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, pull.HasMerged)
|
||||
|
||||
if mergeOptions.Message != "" {
|
||||
gitRepo, err := git.OpenRepository(t.Context(), repository)
|
||||
require.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
commit, err := gitRepo.GetCommit(t.Context(), pull.MergedCommitID)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, commit.CommitMessage.MessageRaw, mergeOptions.Message)
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
@@ -116,8 +127,8 @@ func TestPullMerge(t *testing.T) {
|
||||
elem := strings.Split(test.RedirectURL(resp), "/")
|
||||
assert.Equal(t, "pulls", elem[3])
|
||||
testPullMerge(t, session, elem[1], elem[2], elem[4], MergeOptions{
|
||||
Style: repo_model.MergeStyleMerge,
|
||||
DeleteBranch: false,
|
||||
Style: repo_model.MergeStyleMerge,
|
||||
Message: strings.Repeat("x", 200*1024),
|
||||
})
|
||||
|
||||
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repo.ID})
|
||||
|
||||
Reference in New Issue
Block a user