Skip to content

Commit

Permalink
Fix bug when deleting a migrated branch (#32075)
Browse files Browse the repository at this point in the history
After migrating a repository with pull request, the branch is missed and
after the pull request merged, the branch cannot be deleted.
  • Loading branch information
lunny authored Sep 24, 2024
1 parent 4947bec commit 5a85684
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions services/repository/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,22 +483,23 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
}

rawBranch, err := git_model.GetBranch(ctx, repo.ID, branchName)
if err != nil {
if err != nil && !git_model.IsErrBranchNotExist(err) {
return fmt.Errorf("GetBranch: %vc", err)
}

if rawBranch.IsDeleted {
return nil
}
// database branch record not exist or it's a deleted branch
notExist := git_model.IsErrBranchNotExist(err) || rawBranch.IsDeleted

commit, err := gitRepo.GetBranchCommit(branchName)
if err != nil {
return err
}

if err := db.WithTx(ctx, func(ctx context.Context) error {
if err := git_model.AddDeletedBranch(ctx, repo.ID, branchName, doer.ID); err != nil {
return err
if !notExist {
if err := git_model.AddDeletedBranch(ctx, repo.ID, branchName, doer.ID); err != nil {
return err
}
}

return gitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
Expand Down

0 comments on commit 5a85684

Please sign in to comment.