diff --git a/integrations/pull_status_test.go b/integrations/pull_status_test.go index a5247f56ec5f3..5495486b75899 100644 --- a/integrations/pull_status_test.go +++ b/integrations/pull_status_test.go @@ -105,7 +105,12 @@ func doAPICreateCommitStatus(ctx APITestContext, commitID string, status api.Com } } -func TestPullCreate_EmptyChangesWithCommits(t *testing.T) { +func TestPullCreate_EmptyChangesWithDifferentCommits(t *testing.T) { + // Merge must continue if commits SHA are different, even if content is same + // Reason: gitflow and merging master back into develop, where is high possiblity, there are no changes + // but just commit saying "Merge branch". And this meta commit can be also tagged, + // so we need to have this meta commit also in develop branch. + onGiteaRun(t, func(t *testing.T, u *url.URL) { session := loginUser(t, "user1") testRepoFork(t, session, "user2", "repo1", "user1", "repo1") @@ -125,6 +130,30 @@ func TestPullCreate_EmptyChangesWithCommits(t *testing.T) { resp := session.MakeRequest(t, req, http.StatusOK) doc := NewHTMLParser(t, resp.Body) + text := strings.TrimSpace(doc.doc.Find(".merge-section").Text()) + assert.Contains(t, text, "This pull request can be merged automatically.") + }) +} + +func TestPullCreate_EmptyChangesWithSameCommits(t *testing.T) { + onGiteaRun(t, func(t *testing.T, u *url.URL) { + session := loginUser(t, "user1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testCreateBranch(t, session, "user1", "repo1", "branch/master", "status1", http.StatusSeeOther) + + url := path.Join("user1", "repo1", "compare", "master...status1") + req := NewRequestWithValues(t, "POST", url, + map[string]string{ + "_csrf": GetCSRF(t, session, url), + "title": "pull request from status1", + }, + ) + session.MakeRequest(t, req, http.StatusSeeOther) + + req = NewRequest(t, "GET", "/user1/repo1/pulls/1") + resp := session.MakeRequest(t, req, http.StatusOK) + doc := NewHTMLParser(t, resp.Body) + text := strings.TrimSpace(doc.doc.Find(".merge-section").Text()) assert.Contains(t, text, "This branch is equal with the target branch.") }) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 6e8f575ad54a5..846f398cf4346 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -1210,6 +1210,7 @@ func CompareAndPullRequestPost(ctx *context.Context) { BaseRepo: repo, MergeBase: ci.CompareInfo.MergeBase, Type: issues_model.PullRequestGitea, + HeadCommitID: ci.CompareInfo.HeadCommitID, AllowMaintainerEdit: form.AllowMaintainerEdit, } // FIXME: check error in the case two people send pull request at almost same time, give nice error prompt diff --git a/services/pull/patch.go b/services/pull/patch.go index c7a69501c32f0..ac8548188b08f 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -284,18 +284,14 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo * } if !conflict { - var treeHash string - treeHash, _, err = git.NewCommand(ctx, "write-tree").RunStdString(&git.RunOpts{Dir: tmpBasePath}) - if err != nil { - return false, err - } - treeHash = strings.TrimSpace(treeHash) - baseTree, err := gitRepo.GetTree("base") - if err != nil { - return false, err - } - if treeHash == baseTree.ID.String() { - log.Debug("PullRequest[%d]: Patch is empty - ignoring", pr.ID) + log.Debug("PullRequest[%d]: Head SHA: %s, Merge base SHA: %s", pr.ID, pr.HeadCommitID, pr.MergeBase) + if pr.HeadCommitID == pr.MergeBase { + // Merge must continue if commits SHA are different, even if content is same + // Reason: gitflow and merging master back into develop, where is high possiblity, there are no changes + // but just commit saying "Merge branch". And this meta commit can be also tagged, + // so we need to have this meta commit also in develop branch. + + log.Debug("PullRequest[%d]: Commits are equal - ignoring", pr.ID) pr.Status = issues_model.PullRequestStatusEmpty }