fix(pull): refresh commits behind when an AGit pull request is updated (#39613) (#39625)

Backport #39613 by @dziulatex

Fixes #39598

When the base branch has "Block merge if the pull request is outdated"
enabled, an AGit pull request that fell behind could never be unblocked:
merging the base branch into the topic and pushing it again to the same
`refs/for/<branch>/<topic>` left the PR "blocked because it's outdated"
forever.

The outdated block reads the stored `commits_behind`. Pushing a branch
refreshes it for GitHub-flow PRs (`AddTestPullRequestTask`), but the
AGit update path in `services/agit` moved `refs/pull/N/head` without
recomputing it, so the value only changed when the base branch was
pushed, which is the event that makes a PR behind again.

The AGit update path now calls `syncCommitDivergence` in
`UpdateRefForAgit`, the same as AGit PR creation (`NewPullRequest`)
already does.

Signed-off-by: dziulatex <paweldziurasoftware@yahoo.com>
Co-authored-by: dziulatex <38464243+dziulatex@users.noreply.github.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-10-06 11:27:16 +00:00
1 parent 15a0ea83ca
commit 69a2bfcfbd
3 files changed
+25 -25

No files matched your search

+5
View File
@@ -109,6 +109,8 @@ func TestAgitPullPush(t *testing.T) {
assert.NoError(t, pr.LoadIssue(t.Context()))
assert.Equal(t, "test-title", pr.Issue.Title)
assert.Equal(t, "test-description", pr.Issue.Content)
assert.Equal(t, 0, pr.CommitsBehind)
assert.Equal(t, 1, pr.CommitsAhead)
// commit 2
_, err = generateCommitWithNewData(t.Context(), testFileSizeSmall, dstPath, "user2@example.com", "User Two", "branch-data-file-2-")
@@ -119,6 +121,9 @@ func TestAgitPullPush(t *testing.T) {
WithDir(dstPath).
Run(t.Context())
assert.NoError(t, err)
pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: 1, Flow: issues_model.PullRequestFlowAGit, HeadBranch: "user2/test-agit-push"})
assert.Equal(t, 0, pr.CommitsBehind)
assert.Equal(t, 2, pr.CommitsAhead)
// reset to first commit
err = gitcmd.NewCommand("reset", "--hard", "HEAD~1").WithDir(dstPath).Run(t.Context())