From 0bcf644da4c3d21fad3ce8f33ccc26f8110568d6 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 28 Dec 2019 03:17:37 +0800 Subject: [PATCH] Fix deleted branch isn't removed when push the branch again (#9516) --- models/branches.go | 6 ++++++ modules/repofiles/update.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/models/branches.go b/models/branches.go index 045019314..21b23c75d 100644 --- a/models/branches.go +++ b/models/branches.go @@ -525,6 +525,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(ctx context.Context) { // Nothing to do for shutdown or terminate diff --git a/modules/repofiles/update.go b/modules/repofiles/update.go index c97d3d46e..19c3d5b51 100644 --- a/modules/repofiles/update.go +++ b/modules/repofiles/update.go @@ -520,6 +520,12 @@ func PushUpdates(repo *models.Repository, optsList []*PushUpdateOptions) error { } } + if opts.NewCommitID != git.EmptySHA { + if err = models.RemoveDeletedBranch(repo.ID, opts.Branch); err != nil { + log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, opts.Branch, err) + } + } + log.Trace("TriggerTask '%s/%s' by %s", repo.Name, opts.Branch, pusher.Name) go pull_service.AddTestPullRequestTask(pusher, repo.ID, opts.Branch, true)