From 88a74c50f7af1524d5ecceda7d65b21a64d9662b Mon Sep 17 00:00:00 2001 From: george Date: Sat, 17 Jan 2026 02:57:17 -0800 Subject: [PATCH] fix(polecat): prune stale worktree entries on early return in RemoveWithOptions When repoBase() fails in RemoveWithOptions, the function previously returned early after removing the directory but without calling WorktreePrune(). This could leave stale worktree entries in .git/worktrees/ if the polecat was created before the repo base became unavailable. Now we attempt to prune from both possible repo locations (bare repo and mayor/rig) before the early return. This is a best-effort cleanup that handles edge cases where the repo base is corrupted but worktree entries still exist. Resolves: gt-wisp-618ar Co-Authored-By: Claude Opus 4.5 --- internal/polecat/manager.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/polecat/manager.go b/internal/polecat/manager.go index e3d0df93..e23d7abc 100644 --- a/internal/polecat/manager.go +++ b/internal/polecat/manager.go @@ -432,6 +432,18 @@ func (m *Manager) RemoveWithOptions(name string, force, nuclear bool) error { // Get repo base to remove the worktree properly repoGit, err := m.repoBase() if err != nil { + // Best-effort: try to prune stale worktree entries from both possible repo locations. + // This handles edge cases where the repo base is corrupted but worktree entries exist. + bareRepoPath := filepath.Join(m.rig.Path, ".repo.git") + if info, statErr := os.Stat(bareRepoPath); statErr == nil && info.IsDir() { + bareGit := git.NewGitWithDir(bareRepoPath, "") + _ = bareGit.WorktreePrune() + } + mayorRigPath := filepath.Join(m.rig.Path, "mayor", "rig") + if info, statErr := os.Stat(mayorRigPath); statErr == nil && info.IsDir() { + mayorGit := git.NewGit(mayorRigPath) + _ = mayorGit.WorktreePrune() + } // Fall back to direct removal if repo base not found return os.RemoveAll(polecatDir) }