aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-09-24 15:42:08 +0800
committerGitHub <noreply@github.com>2024-09-24 07:42:08 +0000
commit5a8568459d22e57cac506465463660526ca6a08f (patch)
tree168fb28328f67bb296ed4462d58cff4354aa2968
parent4947bec8360c152daca23e120eae1732d3848492 (diff)
downloadgitea-5a8568459d22e57cac506465463660526ca6a08f.tar.gz
gitea-5a8568459d22e57cac506465463660526ca6a08f.zip
Fix bug when deleting a migrated branch (#32075)
After migrating a repository with pull request, the branch is missed and after the pull request merged, the branch cannot be deleted.
-rw-r--r--services/repository/branch.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/services/repository/branch.go b/services/repository/branch.go
index 7fc9993077..f5cdb72a7b 100644
--- a/services/repository/branch.go
+++ b/services/repository/branch.go
@@ -483,13 +483,12 @@ 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 {
@@ -497,8 +496,10 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
}
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{