diff --git a/internal/cmd/polecat.go b/internal/cmd/polecat.go index 54df8d1d..7948ed51 100644 --- a/internal/cmd/polecat.go +++ b/internal/cmd/polecat.go @@ -1203,8 +1203,15 @@ func runPolecatNuke(cmd *cobra.Command, args []string) error { } // Step 4: Delete branch (if we know it) + // Use bare repo if it exists (matches where worktree was created), otherwise mayor/rig if branchToDelete != "" { - repoGit := git.NewGit(filepath.Join(p.r.Path, "mayor", "rig")) + var repoGit *git.Git + bareRepoPath := filepath.Join(p.r.Path, ".repo.git") + if info, err := os.Stat(bareRepoPath); err == nil && info.IsDir() { + repoGit = git.NewGitWithDir(bareRepoPath, "") + } else { + repoGit = git.NewGit(filepath.Join(p.r.Path, "mayor", "rig")) + } if err := repoGit.DeleteBranch(branchToDelete, true); err != nil { // Non-fatal - branch might already be gone fmt.Printf(" %s branch delete: %v\n", style.Dim.Render("○"), err) diff --git a/internal/polecat/manager.go b/internal/polecat/manager.go index 421fad60..e3d0df93 100644 --- a/internal/polecat/manager.go +++ b/internal/polecat/manager.go @@ -445,21 +445,17 @@ func (m *Manager) RemoveWithOptions(name string, force, nuclear bool) error { } } else { // GT-1L3MY9: git worktree remove may leave untracked directories behind. - // Clean up any leftover .beads/ directory that wasn't fully removed. - cloneBeadsDir := filepath.Join(clonePath, ".beads") - _ = os.RemoveAll(cloneBeadsDir) - // Remove the now-empty clonePath if it still exists - _ = os.Remove(clonePath) + // Clean up any leftover files (overlay files, .beads/, setup hook outputs, etc.) + // Use RemoveAll to handle non-empty directories with untracked files. + _ = os.RemoveAll(clonePath) } - // Also remove the parent polecat directory if it's now empty + // Also remove the parent polecat directory // (for new structure: polecats// contains only polecats///) if polecatDir != clonePath { - // GT-1L3MY9: Clean up any orphaned .beads/ directory at polecat level. - // This can happen if the worktree cleanup was incomplete or from old state. - polecatBeadsDir := filepath.Join(polecatDir, ".beads") - _ = os.RemoveAll(polecatBeadsDir) - _ = os.Remove(polecatDir) // Non-fatal: only removes if empty + // GT-1L3MY9: Clean up any orphaned files at polecat level. + // Use RemoveAll to handle non-empty directories with leftover files. + _ = os.RemoveAll(polecatDir) } // Prune any stale worktree entries (non-fatal: cleanup only)