Skip to content

Commit 0bcf644

Browse files
lunnyzeripath
authored andcommitted
Fix deleted branch isn't removed when push the branch again (#9516)
1 parent e3a5b83 commit 0bcf644

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

models/branches.go

+6
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,12 @@ func (deletedBranch *DeletedBranch) LoadUser() {
525525
deletedBranch.DeletedBy = user
526526
}
527527

528+
// RemoveDeletedBranch removes all deleted branches
529+
func RemoveDeletedBranch(repoID int64, branch string) error {
530+
_, err := x.Where("repo_id=? AND name=?", repoID, branch).Delete(new(DeletedBranch))
531+
return err
532+
}
533+
528534
// RemoveOldDeletedBranches removes old deleted branches
529535
func RemoveOldDeletedBranches(ctx context.Context) {
530536
// Nothing to do for shutdown or terminate

modules/repofiles/update.go

+6
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,12 @@ func PushUpdates(repo *models.Repository, optsList []*PushUpdateOptions) error {
520520
}
521521
}
522522

523+
if opts.NewCommitID != git.EmptySHA {
524+
if err = models.RemoveDeletedBranch(repo.ID, opts.Branch); err != nil {
525+
log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, opts.Branch, err)
526+
}
527+
}
528+
523529
log.Trace("TriggerTask '%s/%s' by %s", repo.Name, opts.Branch, pusher.Name)
524530

525531
go pull_service.AddTestPullRequestTask(pusher, repo.ID, opts.Branch, true)

0 commit comments

Comments
 (0)