Fix branch deletion for squash or rebase merged pull requests (#3425)
This commit is contained in:
		
							parent
							
								
									5911f98392
								
							
						
					
					
						commit
						ca4f5c37e6
					
				| 
						 | 
					@ -957,37 +957,21 @@ func CleanUpPullRequest(ctx *context.Context) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check if branch has no new commits
 | 
						// Check if branch has no new commits
 | 
				
			||||||
	if len(pr.MergedCommitID) > 0 {
 | 
						headCommitID, err := gitBaseRepo.GetRefCommitID(pr.GetGitRefName())
 | 
				
			||||||
		branchCommitID, err := gitRepo.GetBranchCommitID(pr.HeadBranch)
 | 
						if err != nil {
 | 
				
			||||||
		if err != nil {
 | 
							log.Error(4, "GetRefCommitID: %v", err)
 | 
				
			||||||
			log.Error(4, "GetBranchCommitID: %v", err)
 | 
							ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
 | 
				
			||||||
			ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
 | 
							return
 | 
				
			||||||
			return
 | 
						}
 | 
				
			||||||
		}
 | 
						branchCommitID, err := gitRepo.GetBranchCommitID(pr.HeadBranch)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		commit, err := gitBaseRepo.GetCommit(pr.MergedCommitID)
 | 
							log.Error(4, "GetBranchCommitID: %v", err)
 | 
				
			||||||
		if err != nil {
 | 
							ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
 | 
				
			||||||
			log.Error(4, "GetCommit: %v", err)
 | 
							return
 | 
				
			||||||
			ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
 | 
						}
 | 
				
			||||||
			return
 | 
						if headCommitID != branchCommitID {
 | 
				
			||||||
		}
 | 
							ctx.Flash.Error(ctx.Tr("repo.branch.delete_branch_has_new_commits", fullBranchName))
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
		isParent := false
 | 
					 | 
				
			||||||
		for i := 0; i < commit.ParentCount(); i++ {
 | 
					 | 
				
			||||||
			if parent, err := commit.Parent(i); err != nil {
 | 
					 | 
				
			||||||
				log.Error(4, "Parent: %v", err)
 | 
					 | 
				
			||||||
				ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
 | 
					 | 
				
			||||||
				return
 | 
					 | 
				
			||||||
			} else if parent.ID.String() == branchCommitID {
 | 
					 | 
				
			||||||
				isParent = true
 | 
					 | 
				
			||||||
				break
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if !isParent {
 | 
					 | 
				
			||||||
			ctx.Flash.Error(ctx.Tr("repo.branch.delete_branch_has_new_commits", fullBranchName))
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := gitRepo.DeleteBranch(pr.HeadBranch, git.DeleteBranchOptions{
 | 
						if err := gitRepo.DeleteBranch(pr.HeadBranch, git.DeleteBranchOptions{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue