diff --git a/services/repository/branch.go b/services/repository/branch.go index 6e0065b277..df7202227a 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -532,8 +532,8 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R // 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 { + branchCommit, err := gitRepo.GetBranchCommit(branchName) + if err != nil && !errors.Is(err, util.ErrNotExist) { return err } @@ -549,6 +549,9 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R return fmt.Errorf("DeleteBranch: %v", err) } } + if branchCommit == nil { + return nil + } return gitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{ Force: true, @@ -557,20 +560,24 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R return err } - objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName) + if branchCommit == nil { + return nil + } // Don't return error below this + + objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName) if err := PushUpdate( &repo_module.PushUpdateOptions{ RefFullName: git.RefNameFromBranch(branchName), - OldCommitID: commit.ID.String(), + OldCommitID: branchCommit.ID.String(), NewCommitID: objectFormat.EmptyObjectID().String(), PusherID: doer.ID, PusherName: doer.Name, RepoUserName: repo.OwnerName, RepoName: repo.Name, }); err != nil { - log.Error("Update: %v", err) + log.Error("PushUpdateOptions: %v", err) } return nil