Skip to content

Commit

Permalink
Fix deleted branch isn't removed when push the branch again (#9516) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored Dec 28, 2019
1 parent a3928fd commit 9409ac9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions models/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,12 @@ func (deletedBranch *DeletedBranch) LoadUser() {
deletedBranch.DeletedBy = user
}

// RemoveDeletedBranch removes all deleted branches
func RemoveDeletedBranch(repoID int64, branch string) error {
_, err := x.Where("repo_id=? AND name=?", repoID, branch).Delete(new(DeletedBranch))
return err
}

// RemoveOldDeletedBranches removes old deleted branches
func RemoveOldDeletedBranches() {
log.Trace("Doing: DeletedBranchesCleanup")
Expand Down
7 changes: 6 additions & 1 deletion modules/repofiles/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,15 @@ func PushUpdate(repo *models.Repository, branch string, opts models.PushUpdateOp
}
}
} else if !isDelRef {
branchName := opts.RefFullName[len(git.BranchPrefix):]
if err = models.RemoveDeletedBranch(repo.ID, branchName); err != nil {
log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, branchName, err)
}

// If is branch reference

// Clear cache for branch commit count
cache.Remove(repo.GetCommitsCountCacheKey(opts.RefFullName[len(git.BranchPrefix):], true))
cache.Remove(repo.GetCommitsCountCacheKey(branchName, true))

newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
if err != nil {
Expand Down

0 comments on commit 9409ac9

Please sign in to comment.