mirror of
https://github.com/go-gitea/gitea
synced 2024-11-28 20:32:56 +01:00
Backport #32075 by @lunny After migrating a repository with pull request, the branch is missed and after the pull request merged, the branch cannot be deleted. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
5c73da7c54
commit
1ef74004a2
1 changed files with 7 additions and 6 deletions
|
@ -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)
|
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)
|
return fmt.Errorf("GetBranch: %vc", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rawBranch.IsDeleted {
|
// database branch record not exist or it's a deleted branch
|
||||||
return nil
|
notExist := git_model.IsErrBranchNotExist(err) || rawBranch.IsDeleted
|
||||||
}
|
|
||||||
|
|
||||||
commit, err := gitRepo.GetBranchCommit(branchName)
|
commit, err := gitRepo.GetBranchCommit(branchName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -497,9 +496,11 @@ 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 := db.WithTx(ctx, func(ctx context.Context) error {
|
||||||
|
if !notExist {
|
||||||
if err := git_model.AddDeletedBranch(ctx, repo.ID, branchName, doer.ID); err != nil {
|
if err := git_model.AddDeletedBranch(ctx, repo.ID, branchName, doer.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return gitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
|
return gitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
|
||||||
Force: true,
|
Force: true,
|
||||||
|
|
Loading…
Reference in a new issue