Skip to content

Commit 0e7550f

Browse files
committed
Allow empty commit when merging pull request with squash style
1 parent 98eb2b0 commit 0e7550f

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,34 @@ func TestPullSquash(t *testing.T) {
240240
})
241241
}
242242

243+
func TestPullSquashMergeEmpty(t *testing.T) {
244+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
245+
session := loginUser(t, "user1")
246+
testEditFileToNewBranch(t, session, "user2", "repo1", "master", "pr-squash-empty", "README.md", "Hello, World (Edited)\n")
247+
resp := testPullCreate(t, session, "user2", "repo1", false, "master", "pr-squash-empty", "This is a pull title")
248+
249+
elem := strings.Split(test.RedirectURL(resp), "/")
250+
assert.Equal(t, "pulls", elem[3])
251+
252+
httpContext := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository)
253+
dstPath := t.TempDir()
254+
255+
u.Path = httpContext.GitPath()
256+
u.User = url.UserPassword("user2", userPassword)
257+
258+
t.Run("Clone", doGitClone(dstPath, u))
259+
doGitCheckoutBranch(dstPath, "-b", "pr-squash-empty", "remotes/origin/pr-squash-empty")(t)
260+
doGitMerge(dstPath, "pr-squash-empty")(t)
261+
262+
doGitPushTestRepository(dstPath)(t)
263+
264+
testPullMerge(t, session, elem[1], elem[2], elem[4], MergeOptions{
265+
Style: repo_model.MergeStyleSquash,
266+
DeleteBranch: false,
267+
})
268+
})
269+
}
270+
243271
func TestPullSquashWithHeadCommitID(t *testing.T) {
244272
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
245273
hookTasks, err := webhook.HookTasks(t.Context(), 1, 1) // Retrieve previous hook number

0 commit comments

Comments
 (0)