diff options
author | Lauris BH <lauris@nix.lv> | 2018-01-30 14:29:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-30 14:29:39 +0200 |
commit | ca4f5c37e640a64fe512a316786033778c27b201 (patch) | |
tree | 6e0608dba41098256e0b531f476e80ff159d2213 /routers | |
parent | 5911f98392e1b7a04fcd570092a8089d1caff91d (diff) | |
download | gitea-ca4f5c37e640a64fe512a316786033778c27b201.tar.gz gitea-ca4f5c37e640a64fe512a316786033778c27b201.zip |
Fix branch deletion for squash or rebase merged pull requests (#3425)
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/pull.go | 46 |
1 files changed, 15 insertions, 31 deletions
diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 1db1e6327a..a852cee1f3 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -957,37 +957,21 @@ func CleanUpPullRequest(ctx *context.Context) { } // Check if branch has no new commits - if len(pr.MergedCommitID) > 0 { - branchCommitID, err := gitRepo.GetBranchCommitID(pr.HeadBranch) - if err != nil { - log.Error(4, "GetBranchCommitID: %v", err) - ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName)) - return - } - - commit, err := gitBaseRepo.GetCommit(pr.MergedCommitID) - if err != nil { - log.Error(4, "GetCommit: %v", err) - ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", 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 - } + headCommitID, err := gitBaseRepo.GetRefCommitID(pr.GetGitRefName()) + if err != nil { + log.Error(4, "GetRefCommitID: %v", err) + ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName)) + return + } + branchCommitID, err := gitRepo.GetBranchCommitID(pr.HeadBranch) + if err != nil { + log.Error(4, "GetBranchCommitID: %v", err) + 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 } if err := gitRepo.DeleteBranch(pr.HeadBranch, git.DeleteBranchOptions{ |