Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions services/repository/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,14 @@ 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 {
return err
branchExistInGit := gitRepo.IsBranchExist(branchName)
var commitID string
if branchExistInGit {
commit, err := gitRepo.GetBranchCommit(branchName)
if err != nil {
return err
}
commitID = commit.ID.String()
}

if err := db.WithTx(ctx, func(ctx context.Context) error {
Expand All @@ -549,6 +554,9 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
return fmt.Errorf("DeleteBranch: %v", err)
}
}
if !branchExistInGit {
return nil
}

return gitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
Force: true,
Expand All @@ -557,20 +565,22 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
return err
}

objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)

// Don't return error below this
if err := PushUpdate(
&repo_module.PushUpdateOptions{
RefFullName: git.RefNameFromBranch(branchName),
OldCommitID: commit.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)
if branchExistInGit {
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)

// Don't return error below this
if err := PushUpdate(
&repo_module.PushUpdateOptions{
RefFullName: git.RefNameFromBranch(branchName),
OldCommitID: commitID,
NewCommitID: objectFormat.EmptyObjectID().String(),
PusherID: doer.ID,
PusherName: doer.Name,
RepoUserName: repo.OwnerName,
RepoName: repo.Name,
}); err != nil {
log.Error("Update: %v", err)
}
}

return nil
Expand Down