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 <noreply@anthropic.com>
This commit is contained in:
george
2026-01-17 02:57:17 -08:00
committed by beads/crew/emma
parent 7ff87ff012
commit 88a74c50f7

View File

@@ -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)
}