]> source.dussan.org Git - gitea.git/commitdiff
Fix deleted branch isn't removed when push the branch again (#9516)
authorLunny Xiao <xiaolunwen@gmail.com>
Fri, 27 Dec 2019 19:17:37 +0000 (03:17 +0800)
committerzeripath <art27@cantab.net>
Fri, 27 Dec 2019 19:17:37 +0000 (19:17 +0000)
models/branches.go
modules/repofiles/update.go

index 045019314aa648ff9e770a3d16ef6696bccf7723..21b23c75d92dc33e0526b83bcd791ee76f38c5ef 100644 (file)
@@ -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
index c97d3d46e44299aff5b5e3ca4a77ee937bab599b..19c3d5b51c44b326aa8684457ffe62a703b546f0 100644 (file)
@@ -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)