diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml index fbc0d504f8..79051ffb6c 100644 --- a/models/fixtures/pull_request.yml +++ b/models/fixtures/pull_request.yml @@ -65,6 +65,7 @@ merge_base: 985f0301dba5e7b34be866819cd15ad3d8f508ee has_merged: false allow_maintainer_edit: true + commits_behind: 1 - id: 6 diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 43968c1898..bb89e30d54 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -14,7 +14,6 @@ import ( "net/url" "strconv" "strings" - "time" "forgejo.org/models" activities_model "forgejo.org/models/activities" @@ -728,7 +727,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C ctx.Data["HeadBranchCommitID"] = headBranchSha ctx.Data["PullHeadCommitID"] = sha - if pull.HeadRepo == nil || !headBranchExist || (!pull.Issue.IsClosed && (headBranchSha != sha)) { + if pull.HeadRepo == nil || !headBranchExist || (!pull.Issue.IsClosed && !pull.IsChecking() && (headBranchSha != sha)) { ctx.Data["IsPullRequestBroken"] = true if pull.IsSameRepo() { ctx.Data["HeadTarget"] = pull.HeadBranch @@ -1208,8 +1207,6 @@ func UpdatePullRequest(ctx *context.Context) { return } - time.Sleep(1 * time.Second) - ctx.Flash.Success(ctx.Tr("repo.pulls.update_branch_success")) ctx.Redirect(issue.Link()) } diff --git a/tests/integration/pull_update_test.go b/tests/integration/pull_update_test.go index bb3f0ed744..975b21a239 100644 --- a/tests/integration/pull_update_test.go +++ b/tests/integration/pull_update_test.go @@ -273,3 +273,19 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *issues_mod return issue.PullRequest } + +func TestStatusDuringUpdate(t *testing.T) { + onGiteaRun(t, func(t *testing.T, u *url.URL) { + session := loginUser(t, "user2") + + // Adjust this pull request to be in the conflict checker and having a head + // branch that is pointing to the an incorrect commit ID. + _, err := db.GetEngine(t.Context()).Cols("status", "head_branch").Update(&issues_model.PullRequest{ID: 5, Status: issues_model.PullRequestStatusChecking, HeadBranch: "master"}) + require.NoError(t, err) + + resp := session.MakeRequest(t, NewRequest(t, "GET", "/user2/repo1/pulls/5"), http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + assert.Contains(t, htmlDoc.Find(".merge-section .item").Text(), "Merge conflict checking is in progress. Try again in few moments.") + }) +}