Skip to content

Commit 91901c2

Browse files
authored
Allow empty commit when merging pull request with squash style (#35989) (#36003)
1 parent 20cf4b7 commit 91901c2

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,3 +1110,33 @@ func TestPullNonMergeForAdminWithBranchProtection(t *testing.T) {
11101110
session.MakeRequest(t, mergeReq, http.StatusMethodNotAllowed)
11111111
})
11121112
}
1113+
1114+
func TestPullSquashMergeEmpty(t *testing.T) {
1115+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
1116+
session := loginUser(t, "user1")
1117+
testEditFileToNewBranch(t, session, "user2", "repo1", "master", "pr-squash-empty", "README.md", "Hello, World (Edited)\n")
1118+
resp := testPullCreate(t, session, "user2", "repo1", false, "master", "pr-squash-empty", "This is a pull title")
1119+
1120+
elem := strings.Split(test.RedirectURL(resp), "/")
1121+
assert.Equal(t, "pulls", elem[3])
1122+
1123+
httpContext := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository)
1124+
dstPath := t.TempDir()
1125+
1126+
u.Path = httpContext.GitPath()
1127+
u.User = url.UserPassword("user2", userPassword)
1128+
1129+
t.Run("Clone", doGitClone(dstPath, u))
1130+
doGitCheckoutBranch(dstPath, "-b", "pr-squash-empty", "remotes/origin/pr-squash-empty")(t)
1131+
doGitCheckoutBranch(dstPath, "master")(t)
1132+
_, _, err := gitcmd.NewCommand("cherry-pick").AddArguments("pr-squash-empty").
1133+
RunStdString(t.Context(), &gitcmd.RunOpts{
1134+
Dir: dstPath,
1135+
})
1136+
assert.NoError(t, err)
1137+
1138+
doGitPushTestRepository(dstPath)(t)
1139+
1140+
testPullMerge(t, session, elem[1], elem[2], elem[4], repo_model.MergeStyleSquash, false)
1141+
})
1142+
}

0 commit comments

Comments
 (0)