@@ -284,21 +284,35 @@ func (ops *deferredFetchOps) reconcile(ctx context.Context, g *git.Git, headBran
284284 }
285285
286286 if len (ops .deletedRefs ) > 0 {
287+ const oldNamespace = "refs/gg-old/"
288+ deleteOldOlds := make (map [git.Ref ]git.RefMutation )
289+ for ref := range ops .localRefs {
290+ if strings .HasPrefix (string (ref ), oldNamespace ) {
291+ deleteOldOlds [ref ] = git .DeleteRef ()
292+ }
293+ }
294+ if err := g .MutateRefs (ctx , deleteOldOlds ); err != nil {
295+ return err
296+ }
297+
287298 mutations := make (map [git.Ref ]git.RefMutation )
288- branchDeleteArgs := []string { "branch" , "-D" , "--" }
299+ var branchesToDelete []string
289300 for ref , expectHash := range ops .deletedRefs {
290301 val := expectHash .String ()
291302 if branchName := ref .Branch (); branchName != "" {
292- mutations [git .Ref ("refs/gg-old/" + branchName )] = git .SetRef (val )
293- branchDeleteArgs = append (branchDeleteArgs , branchName )
303+ mutations [git .Ref (oldNamespace + branchName )] = git .SetRef (val )
304+ branchesToDelete = append (branchesToDelete , branchName )
294305 } else {
295306 mutations [ref ] = git .DeleteRefIfMatches (val )
296307 }
297308 }
298309 if err := g .MutateRefs (ctx , mutations ); err != nil {
299310 return err
300311 }
301- if err := g .Run (ctx , branchDeleteArgs ... ); err != nil {
312+ err := g .DeleteBranches (ctx , branchesToDelete , git.DeleteBranchOptions {
313+ Force : true ,
314+ })
315+ if err != nil {
302316 return err
303317 }
304318 }
0 commit comments