refactor: Rename RecreateWithOptions to RepairWorktreeWithOptions
Clarify that this operation is for stale state recovery, not normal recycling: - Recreate → RepairWorktree - RecreateWithOptions → RepairWorktreeWithOptions - Updated comments to explain this handles reconciliation when AllocateName returns a name that already exists (stale state needing repair) - Updated polecat_spawn.go output: Recreating → Repairing stale - Updated gc command help text for consistency The function is useful for atomic hook_bead setting during repair, so kept rather than replacing with Remove + Add. Fixes gt-l0lok 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -147,8 +147,8 @@ var polecatGCCmd = &cobra.Command{
|
|||||||
Long: `Garbage collect stale polecat branches in a rig.
|
Long: `Garbage collect stale polecat branches in a rig.
|
||||||
|
|
||||||
Polecats use unique timestamped branches (polecat/<name>-<timestamp>) to
|
Polecats use unique timestamped branches (polecat/<name>-<timestamp>) to
|
||||||
prevent drift issues. Over time, these branches accumulate as polecats
|
prevent drift issues. Over time, these branches accumulate when stale
|
||||||
are recreated.
|
polecats are repaired.
|
||||||
|
|
||||||
This command removes orphaned branches:
|
This command removes orphaned branches:
|
||||||
- Branches for polecats that no longer exist
|
- Branches for polecats that no longer exist
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func SpawnPolecatForSling(rigName string, opts SlingSpawnOptions) (*SpawnedPolec
|
|||||||
}
|
}
|
||||||
fmt.Printf("Allocated polecat: %s\n", polecatName)
|
fmt.Printf("Allocated polecat: %s\n", polecatName)
|
||||||
|
|
||||||
// Check if polecat already exists (shouldn't, since we allocated fresh)
|
// Check if polecat already exists (shouldn't happen - indicates stale state needing repair)
|
||||||
existingPolecat, err := polecatMgr.Get(polecatName)
|
existingPolecat, err := polecatMgr.Get(polecatName)
|
||||||
|
|
||||||
// Build add options with hook_bead set atomically at spawn time
|
// Build add options with hook_bead set atomically at spawn time
|
||||||
@@ -85,7 +85,7 @@ func SpawnPolecatForSling(rigName string, opts SlingSpawnOptions) (*SpawnedPolec
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Exists - recreate with fresh worktree
|
// Stale state: polecat exists despite fresh name allocation - repair it
|
||||||
// Check for uncommitted work first
|
// Check for uncommitted work first
|
||||||
if !opts.Force {
|
if !opts.Force {
|
||||||
pGit := git.NewGit(existingPolecat.ClonePath)
|
pGit := git.NewGit(existingPolecat.ClonePath)
|
||||||
@@ -95,9 +95,9 @@ func SpawnPolecatForSling(rigName string, opts SlingSpawnOptions) (*SpawnedPolec
|
|||||||
polecatName, workStatus.String())
|
polecatName, workStatus.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Printf("Recreating polecat %s with fresh worktree...\n", polecatName)
|
fmt.Printf("Repairing stale polecat %s with fresh worktree...\n", polecatName)
|
||||||
if _, err = polecatMgr.RecreateWithOptions(polecatName, opts.Force, addOpts); err != nil {
|
if _, err = polecatMgr.RepairWorktreeWithOptions(polecatName, opts.Force, addOpts); err != nil {
|
||||||
return nil, fmt.Errorf("recreating polecat: %w", err)
|
return nil, fmt.Errorf("repairing stale polecat: %w", err)
|
||||||
}
|
}
|
||||||
} else if err == polecat.ErrPolecatNotFound {
|
} else if err == polecat.ErrPolecatNotFound {
|
||||||
// Create new polecat
|
// Create new polecat
|
||||||
|
|||||||
@@ -385,20 +385,24 @@ func (m *Manager) ReleaseName(name string) {
|
|||||||
_ = m.namePool.Save() // non-fatal: state file update
|
_ = m.namePool.Save() // non-fatal: state file update
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recreate removes an existing polecat and creates a fresh worktree.
|
// RepairWorktree repairs a stale polecat by removing it and creating a fresh worktree.
|
||||||
// This ensures the polecat starts with the latest code from the base branch.
|
// This is NOT for normal operation - it handles reconciliation when AllocateName
|
||||||
// The name is preserved (not released to pool) since we're recreating immediately.
|
// returns a name that unexpectedly already exists (stale state recovery).
|
||||||
|
//
|
||||||
|
// The polecat starts with the latest code from origin/<default-branch>.
|
||||||
|
// The name is preserved (not released to pool) since we're repairing immediately.
|
||||||
// force controls whether to bypass uncommitted changes check.
|
// force controls whether to bypass uncommitted changes check.
|
||||||
//
|
//
|
||||||
// Branch naming: Each recreation gets a unique branch (polecat/<name>-<timestamp>).
|
// Branch naming: Each repair gets a unique branch (polecat/<name>-<timestamp>).
|
||||||
// Old branches are left for garbage collection - they're never pushed to origin.
|
// Old branches are left for garbage collection - they're never pushed to origin.
|
||||||
func (m *Manager) Recreate(name string, force bool) (*Polecat, error) {
|
func (m *Manager) RepairWorktree(name string, force bool) (*Polecat, error) {
|
||||||
return m.RecreateWithOptions(name, force, AddOptions{})
|
return m.RepairWorktreeWithOptions(name, force, AddOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// RecreateWithOptions removes an existing polecat and creates a fresh worktree with options.
|
// RepairWorktreeWithOptions repairs a stale polecat and creates a fresh worktree with options.
|
||||||
// This allows setting hook_bead atomically at recreation time.
|
// This is NOT for normal operation - see RepairWorktree for context.
|
||||||
func (m *Manager) RecreateWithOptions(name string, force bool, opts AddOptions) (*Polecat, error) {
|
// Allows setting hook_bead atomically at repair time.
|
||||||
|
func (m *Manager) RepairWorktreeWithOptions(name string, force bool, opts AddOptions) (*Polecat, error) {
|
||||||
if !m.exists(name) {
|
if !m.exists(name) {
|
||||||
return nil, ErrPolecatNotFound
|
return nil, ErrPolecatNotFound
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user