From 9409ac9030471de2aad798ec47cc463ddb7ee1ca Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 28 Dec 2019 12:41:41 +0800 Subject: [PATCH] Fix deleted branch isn't removed when push the branch again (#9516) (#9524) --- models/branches.go | 6 ++++++ modules/repofiles/update.go | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/models/branches.go b/models/branches.go index fa8beb866c..3d55cbacd8 100644 --- a/models/branches.go +++ b/models/branches.go @@ -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") diff --git a/modules/repofiles/update.go b/modules/repofiles/update.go index 590eac92b6..62e5a49437 100644 --- a/modules/repofiles/update.go +++ b/modules/repofiles/update.go @@ -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 {