[v12.0/forgejo] fix: prevent pull requests from being merged multiple times (#8862)

Backport of https://codeberg.org/forgejo/forgejo/pulls/8842

Contains a partial cherry-pick of 184e068f37, for the parts the PR depends on. The whole commit is way too involved to cherry-pick as a whole.

Co-authored-by: Danko Aleksejevs <danko@very.lv>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8862
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: BtbN <btbn@btbn.de>
Co-committed-by: BtbN <btbn@btbn.de>
This commit is contained in:
BtbN 2025-08-11 23:08:46 +02:00 committed by Earl Warren
commit 53c4c6bda8
6 changed files with 92 additions and 4 deletions

View file

@ -1445,6 +1445,10 @@ func MergePullRequest(ctx *context.Context) {
log.Debug("MergeUnrelatedHistories error: %v", err)
ctx.Flash.Error(ctx.Tr("repo.pulls.unrelated_histories"))
ctx.JSONRedirect(issue.Link())
} else if models.IsErrPullRequestHasMerged(err) {
log.Debug("MergePullRequestHasMerged error: %v", err)
ctx.Flash.Error(ctx.Tr("repo.pulls.already_merged"))
ctx.JSONRedirect(issue.Link())
} else if git.IsErrPushOutOfDate(err) {
log.Debug("MergePushOutOfDate error: %v", err)
ctx.Flash.Error(ctx.Tr("repo.pulls.merge_out_of_date"))