Skip to content

Commit a60a8c6

Browse files
lunnyZettat123wxiaoguang
authored
Allow empty commit when merging pull request with squash style (go-gitea#35989)
Before this PR, when merging an empty PR with squash style will result in 500. --------- Signed-off-by: wxiaoguang <[email protected]> Co-authored-by: Zettat123 <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 4c51acb commit a60a8c6

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ insert_final_newline = false
2525
[templates/user/auth/oidc_wellknown.tmpl]
2626
indent_style = space
2727

28+
[templates/shared/actions/runner_badge_*.tmpl]
29+
# editconfig lint requires these XML-like files to have charset defined, but the files don't have.
30+
charset = unset
31+
2832
[Makefile]
2933
indent_style = tab
3034

services/pull/merge_squash.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ func doMergeStyleSquash(ctx *mergeContext, message string) error {
7171
}
7272
cmdCommit := gitcmd.NewCommand("commit").
7373
AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email).
74-
AddOptionFormat("--message=%s", message)
74+
AddOptionFormat("--message=%s", message).
75+
AddArguments("--allow-empty")
7576
if ctx.signKey == nil {
7677
cmdCommit.AddArguments("--no-gpg-sign")
7778
} else {

tests/integration/pull_merge_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,3 +1180,35 @@ func TestPullNonMergeForAdminWithBranchProtection(t *testing.T) {
11801180
session.MakeRequest(t, mergeReq, http.StatusMethodNotAllowed)
11811181
})
11821182
}
1183+
1184+
func TestPullSquashMergeEmpty(t *testing.T) {
1185+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
1186+
session := loginUser(t, "user1")
1187+
testEditFileToNewBranch(t, session, "user2", "repo1", "master", "pr-squash-empty", "README.md", "Hello, World (Edited)\n")
1188+
resp := testPullCreate(t, session, "user2", "repo1", false, "master", "pr-squash-empty", "This is a pull title")
1189+
1190+
elem := strings.Split(test.RedirectURL(resp), "/")
1191+
assert.Equal(t, "pulls", elem[3])
1192+
1193+
httpContext := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository)
1194+
dstPath := t.TempDir()
1195+
1196+
u.Path = httpContext.GitPath()
1197+
u.User = url.UserPassword("user2", userPassword)
1198+
1199+
t.Run("Clone", doGitClone(dstPath, u))
1200+
doGitCheckoutBranch(dstPath, "-b", "pr-squash-empty", "remotes/origin/pr-squash-empty")(t)
1201+
doGitCheckoutBranch(dstPath, "master")(t)
1202+
_, _, err := gitcmd.NewCommand("cherry-pick").AddArguments("pr-squash-empty").
1203+
WithDir(dstPath).
1204+
RunStdString(t.Context())
1205+
assert.NoError(t, err)
1206+
1207+
doGitPushTestRepository(dstPath)(t)
1208+
1209+
testPullMerge(t, session, elem[1], elem[2], elem[4], MergeOptions{
1210+
Style: repo_model.MergeStyleSquash,
1211+
DeleteBranch: false,
1212+
})
1213+
})
1214+
}

0 commit comments

Comments
 (0)