summaryrefslogtreecommitdiffstats
path: root/routers/web/repo/pull.go
diff options
context:
space:
mode:
authora1012112796 <1012112796@qq.com>2022-01-04 03:45:58 +0800
committerGitHub <noreply@github.com>2022-01-03 20:45:58 +0100
commit637c3ec5d82f9d727724cc362aea37eeb2f64b40 (patch)
tree2b3af5ec2e6595d037a78b8a45e0a95210ab7d14 /routers/web/repo/pull.go
parent650a50a7ba8efcd8d02c4c93e5abc19f27e6c4b5 (diff)
downloadgitea-637c3ec5d82f9d727724cc362aea37eeb2f64b40.tar.gz
gitea-637c3ec5d82f9d727724cc362aea37eeb2f64b40.zip
Don't delete branch if other PRs with this branch are open (#18164)
fix #18149 Signed-off-by: a1012112796 <1012112796@qq.com>
Diffstat (limited to 'routers/web/repo/pull.go')
-rw-r--r--routers/web/repo/pull.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index 37826abfb4..b40eb1ea17 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -1051,6 +1051,17 @@ func MergePullRequest(ctx *context.Context) {
log.Trace("Pull request merged: %d", pr.ID)
if form.DeleteBranchAfterMerge {
+ // Don't cleanup when other pr use this branch as head branch
+ exist, err := models.HasUnmergedPullRequestsByHeadInfo(pr.HeadRepoID, pr.HeadBranch)
+ if err != nil {
+ ctx.ServerError("HasUnmergedPullRequestsByHeadInfo", err)
+ return
+ }
+ if exist {
+ ctx.Redirect(issue.Link())
+ return
+ }
+
var headRepo *git.Repository
if ctx.Repo != nil && ctx.Repo.Repository != nil && pr.HeadRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil {
headRepo = ctx.Repo.GitRepo
@@ -1222,6 +1233,17 @@ func CleanUpPullRequest(ctx *context.Context) {
return
}
+ // Don't cleanup when there are other PR's that use this branch as head branch.
+ exist, err := models.HasUnmergedPullRequestsByHeadInfo(pr.HeadRepoID, pr.HeadBranch)
+ if err != nil {
+ ctx.ServerError("HasUnmergedPullRequestsByHeadInfo", err)
+ return
+ }
+ if exist {
+ ctx.NotFound("CleanUpPullRequest", nil)
+ return
+ }
+
if err := pr.LoadHeadRepo(); err != nil {
ctx.ServerError("LoadHeadRepo", err)
return