mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-28 16:47:01 +09:00
fix(pull): recover PRs whose recorded merge commit never reached the base repo (#39831)
When pushing the merge commit to the base repo fails (e.g. non-fast-forward), the merge intent recorded by https://github.com/go-gitea/gitea/pull/39442 is left behind. `merged_commit_id` then points to a commit that does not exist in the base repo, and `git branch --contains` fails with `no such commit`, so the PR can never be checked or merged again. - Clear the recorded merge intent if the push fails and the commit is not on the base branch - `IsCommitInBranch` now returns false for a missing commit, so already-stuck PRs recover on the next check Fixes https://github.com/go-gitea/gitea/issues/39824 _Written with Codet assistance._ --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
4 files changed
+77
-2
No files matched your search
@@ -4,8 +4,12 @@
|
||||
package pull
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
issues_model "gitea.dev/models/issues"
|
||||
"gitea.dev/models/unittest"
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/git"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -137,3 +141,19 @@ func TestResolveMergeMessageTemplate(t *testing.T) {
|
||||
assert.Equal(t, "rebase template", tmpl)
|
||||
})
|
||||
}
|
||||
|
||||
func TestMergeIntentWithMissingCommit(t *testing.T) {
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
ctx := t.Context()
|
||||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
||||
require.NoError(t, recordMergeIntent(ctx, pr, &user_model.User{ID: 2}, strings.Repeat("a", 40), false))
|
||||
|
||||
merged, err := hasPullRequestCommitBeenMerged(ctx, pr)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, merged)
|
||||
|
||||
require.NoError(t, clearMergeIntent(ctx, pr))
|
||||
pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
||||
assert.Empty(t, pr.MergedCommitID)
|
||||
assert.Zero(t, pr.MergedUnix)
|
||||
}
|
||||
Reference in new issue
Block a user