mirror of
https://github.com/go-gitea/gitea
synced 2025-08-29 12:58:29 +00:00
Deleting branch could delete broken branch which has database record but git branch is missing (#35360)
For some reasons, branches between database and git are not synced. If a branch exists in database but not in the git, it should be able to be deleted. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user