0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-11-25 23:12:38 +01:00

Allow empty commit when merging pull request with squash style (#35989)

Before this PR, when merging an empty PR with squash style will result
in 500.

---------

Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Zettat123 <zettat123@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Lunny Xiao 2025-11-21 22:02:25 -08:00 committed by GitHub
parent 4c51acb26b
commit a60a8c6966
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 1 deletions

View File

@ -25,6 +25,10 @@ insert_final_newline = false
[templates/user/auth/oidc_wellknown.tmpl] [templates/user/auth/oidc_wellknown.tmpl]
indent_style = space indent_style = space
[templates/shared/actions/runner_badge_*.tmpl]
# editconfig lint requires these XML-like files to have charset defined, but the files don't have.
charset = unset
[Makefile] [Makefile]
indent_style = tab indent_style = tab

View File

@ -71,7 +71,8 @@ func doMergeStyleSquash(ctx *mergeContext, message string) error {
} }
cmdCommit := gitcmd.NewCommand("commit"). cmdCommit := gitcmd.NewCommand("commit").
AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email). AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email).
AddOptionFormat("--message=%s", message) AddOptionFormat("--message=%s", message).
AddArguments("--allow-empty")
if ctx.signKey == nil { if ctx.signKey == nil {
cmdCommit.AddArguments("--no-gpg-sign") cmdCommit.AddArguments("--no-gpg-sign")
} else { } else {

View File

@ -1180,3 +1180,35 @@ func TestPullNonMergeForAdminWithBranchProtection(t *testing.T) {
session.MakeRequest(t, mergeReq, http.StatusMethodNotAllowed) session.MakeRequest(t, mergeReq, http.StatusMethodNotAllowed)
}) })
} }
func TestPullSquashMergeEmpty(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
session := loginUser(t, "user1")
testEditFileToNewBranch(t, session, "user2", "repo1", "master", "pr-squash-empty", "README.md", "Hello, World (Edited)\n")
resp := testPullCreate(t, session, "user2", "repo1", false, "master", "pr-squash-empty", "This is a pull title")
elem := strings.Split(test.RedirectURL(resp), "/")
assert.Equal(t, "pulls", elem[3])
httpContext := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository)
dstPath := t.TempDir()
u.Path = httpContext.GitPath()
u.User = url.UserPassword("user2", userPassword)
t.Run("Clone", doGitClone(dstPath, u))
doGitCheckoutBranch(dstPath, "-b", "pr-squash-empty", "remotes/origin/pr-squash-empty")(t)
doGitCheckoutBranch(dstPath, "master")(t)
_, _, err := gitcmd.NewCommand("cherry-pick").AddArguments("pr-squash-empty").
WithDir(dstPath).
RunStdString(t.Context())
assert.NoError(t, err)
doGitPushTestRepository(dstPath)(t)
testPullMerge(t, session, elem[1], elem[2], elem[4], MergeOptions{
Style: repo_model.MergeStyleSquash,
DeleteBranch: false,
})
})
}