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 13:04:53 +00:00
committed by GitHub
co-authored by wxiaoguang
parent cc34c26172
commit cdf786ce92
21 changed files with 175 additions and 93 deletions
+12 -2
View File
@@ -4,6 +4,7 @@
package context
import (
"errors"
"net/http"
"net/http/httptest"
"net/url"
@@ -27,8 +28,18 @@ func TestRemoveSessionCookieHeader(t *testing.T) {
assert.Contains(t, "other=bar", w.Header().Get("Set-Cookie"))
}
func TestServerErrorFetchActionRespondsJSON(t *testing.T) {
req, _ := http.NewRequest(http.MethodPost, "/", nil)
req.Header.Add("X-Gitea-Fetch-Action", "1")
resp := httptest.NewRecorder()
ctx := NewWebContext(NewBaseContextForTest(t, resp, req), nil, nil)
ctx.ServerError("test", errors.New("boom"))
assert.Equal(t, http.StatusInternalServerError, resp.Code)
assert.Contains(t, resp.Header().Get("Content-Type"), "application/json")
assert.JSONEq(t, `{"errorMessage":"test, error: boom","renderFormat":"text"}`, resp.Body.String())
}
func TestRedirectToCurrentSite(t *testing.T) {
setting.IsInTesting = true
defer test.MockVariableValue(&setting.AppURL, "http://localhost:3000/sub/")()
defer test.MockVariableValue(&setting.AppSubURL, "/sub")()
cases := []struct {
@@ -53,7 +64,6 @@ func TestRedirectToCurrentSite(t *testing.T) {
}
func TestAppFullLink(t *testing.T) {
setting.IsInTesting = true
defer test.MockVariableValue(&setting.AppURL, "https://gitea.example.com/sub/")()
defer test.MockVariableValue(&setting.AppSubURL, "/sub")()
defer test.MockVariableValue(&setting.PublicURLDetection, setting.PublicURLNever)()