File tree 3 files changed +46
-1
lines changed
3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -873,6 +873,17 @@ func MergePullRequest(ctx *context.APIContext) {
873
873
log .Trace ("Pull request merged: %d" , pr .ID )
874
874
875
875
if form .DeleteBranchAfterMerge {
876
+ // Don't cleanup when other pr use this branch as head branch
877
+ prs , err := models .GetUnmergedPullRequestsByHeadInfo (pr .HeadRepoID , pr .HeadBranch )
878
+ if err != nil {
879
+ ctx .ServerError ("GetUnmergedPullRequestsByHeadInfo" , err )
880
+ return
881
+ }
882
+ if len (prs ) > 0 {
883
+ ctx .Status (http .StatusOK )
884
+ return
885
+ }
886
+
876
887
var headRepo * git.Repository
877
888
if ctx .Repo != nil && ctx .Repo .Repository != nil && ctx .Repo .Repository .ID == pr .HeadRepoID && ctx .Repo .GitRepo != nil {
878
889
headRepo = ctx .Repo .GitRepo
Original file line number Diff line number Diff line change @@ -1600,11 +1600,23 @@ func ViewIssue(ctx *context.Context) {
1600
1600
} else {
1601
1601
ctx .Data ["WontSignReason" ] = "not_signed_in"
1602
1602
}
1603
- ctx .Data ["IsPullBranchDeletable" ] = canDelete &&
1603
+
1604
+ isPullBranchDeletable := canDelete &&
1604
1605
pull .HeadRepo != nil &&
1605
1606
git .IsBranchExist (ctx , pull .HeadRepo .RepoPath (), pull .HeadBranch ) &&
1606
1607
(! pull .HasMerged || ctx .Data ["HeadBranchCommitID" ] == ctx .Data ["PullHeadCommitID" ])
1607
1608
1609
+ if isPullBranchDeletable && pull .HasMerged {
1610
+ prs , err := models .GetUnmergedPullRequestsByHeadInfo (pull .HeadRepoID , pull .HeadBranch )
1611
+ if err != nil {
1612
+ ctx .ServerError ("GetUnmergedPullRequestsByHeadInfo" , err )
1613
+ return
1614
+ }
1615
+
1616
+ isPullBranchDeletable = len (prs ) == 0
1617
+ }
1618
+ ctx .Data ["IsPullBranchDeletable" ] = isPullBranchDeletable
1619
+
1608
1620
stillCanManualMerge := func () bool {
1609
1621
if pull .HasMerged || issue .IsClosed || ! ctx .IsSigned {
1610
1622
return false
Original file line number Diff line number Diff line change @@ -1052,6 +1052,17 @@ func MergePullRequest(ctx *context.Context) {
1052
1052
log .Trace ("Pull request merged: %d" , pr .ID )
1053
1053
1054
1054
if form .DeleteBranchAfterMerge {
1055
+ // Don't cleanup when other pr use this branch as head branch
1056
+ prs , err := models .GetUnmergedPullRequestsByHeadInfo (pr .HeadRepoID , pr .HeadBranch )
1057
+ if err != nil {
1058
+ ctx .ServerError ("GetUnmergedPullRequestsByHeadInfo" , err )
1059
+ return
1060
+ }
1061
+ if len (prs ) > 0 {
1062
+ ctx .Redirect (issue .Link ())
1063
+ return
1064
+ }
1065
+
1055
1066
var headRepo * git.Repository
1056
1067
if ctx .Repo != nil && ctx .Repo .Repository != nil && pr .HeadRepoID == ctx .Repo .Repository .ID && ctx .Repo .GitRepo != nil {
1057
1068
headRepo = ctx .Repo .GitRepo
@@ -1261,6 +1272,17 @@ func CleanUpPullRequest(ctx *context.Context) {
1261
1272
return
1262
1273
}
1263
1274
1275
+ // Don't cleanup when other pr use this branch as head branch
1276
+ prs , err := models .GetUnmergedPullRequestsByHeadInfo (pr .HeadRepoID , pr .HeadBranch )
1277
+ if err != nil {
1278
+ ctx .ServerError ("GetUnmergedPullRequestsByHeadInfo" , err )
1279
+ return
1280
+ }
1281
+ if len (prs ) > 0 {
1282
+ ctx .NotFound ("CleanUpPullRequest" , nil )
1283
+ return
1284
+ }
1285
+
1264
1286
if err := pr .LoadHeadRepo (); err != nil {
1265
1287
ctx .ServerError ("LoadHeadRepo" , err )
1266
1288
return
You can’t perform that action at this time.
0 commit comments