fix: crew start rig inference + refactor overlay to shared utility
Two improvements: 1. gt crew start now infers rig from cwd when first arg is not a valid rig name (gt-czltv). Previously, running `gt crew start bob` from within a rig directory would fail because "bob" was treated as the rig name. Now it checks if the arg is a valid rig first. 2. Refactored copyOverlay to shared rig.CopyOverlay utility: - Eliminates code duplication between crew and polecat managers - Preserves source file permissions instead of hardcoding 0644 - Follows PR #278 improvements Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -252,7 +252,7 @@ func (m *Manager) AddWithOptions(name string, opts AddOptions) (*Polecat, error)
|
||||
|
||||
// Copy overlay files from .runtime/overlay/ to polecat root.
|
||||
// This allows services to have .env and other config files at their root.
|
||||
if err := m.copyOverlay(polecatPath); err != nil {
|
||||
if err := rig.CopyOverlay(m.rig.Path, polecatPath); err != nil {
|
||||
// Non-fatal - log warning but continue
|
||||
fmt.Printf("Warning: could not copy overlay files: %v\n", err)
|
||||
}
|
||||
@@ -489,7 +489,7 @@ func (m *Manager) RepairWorktreeWithOptions(name string, force bool, opts AddOpt
|
||||
}
|
||||
|
||||
// Copy overlay files from .runtime/overlay/ to polecat root.
|
||||
if err := m.copyOverlay(polecatPath); err != nil {
|
||||
if err := rig.CopyOverlay(m.rig.Path, polecatPath); err != nil {
|
||||
fmt.Printf("Warning: could not copy overlay files: %v\n", err)
|
||||
}
|
||||
|
||||
@@ -741,62 +741,6 @@ func (m *Manager) setupSharedBeads(polecatPath string) error {
|
||||
return beads.SetupRedirect(townRoot, polecatPath)
|
||||
}
|
||||
|
||||
// copyOverlay copies files from <rig>/.runtime/overlay/ to the worktree root.
|
||||
// This allows storing gitignored files (like .env) that services need at their root.
|
||||
// The overlay is copied non-recursively - only files, not subdirectories.
|
||||
//
|
||||
// Structure:
|
||||
//
|
||||
// rig/
|
||||
// .runtime/
|
||||
// overlay/
|
||||
// .env <- Copied to polecat root
|
||||
// config.json <- Copied to polecat root
|
||||
// polecats/
|
||||
// <name>/
|
||||
// .env <- Copied from overlay
|
||||
// config.json <- Copied from overlay
|
||||
func (m *Manager) copyOverlay(polecatPath string) error {
|
||||
overlayDir := filepath.Join(m.rig.Path, ".runtime", "overlay")
|
||||
|
||||
// Check if overlay directory exists
|
||||
entries, err := os.ReadDir(overlayDir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
// No overlay directory - not an error, just nothing to copy
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("reading overlay dir: %w", err)
|
||||
}
|
||||
|
||||
// Copy each file (not directories) from overlay to polecat root
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() {
|
||||
// Skip subdirectories - only copy files at overlay root
|
||||
continue
|
||||
}
|
||||
|
||||
srcPath := filepath.Join(overlayDir, entry.Name())
|
||||
dstPath := filepath.Join(polecatPath, entry.Name())
|
||||
|
||||
// Read source file
|
||||
data, err := os.ReadFile(srcPath)
|
||||
if err != nil {
|
||||
// Log warning but continue - don't fail spawn for overlay issues
|
||||
fmt.Printf("Warning: could not read overlay file %s: %v\n", entry.Name(), err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Write to destination
|
||||
if err := os.WriteFile(dstPath, data, 0644); err != nil {
|
||||
fmt.Printf("Warning: could not write overlay file %s: %v\n", entry.Name(), err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CleanupStaleBranches removes orphaned polecat branches that are no longer in use.
|
||||
// This includes:
|
||||
// - Branches for polecats that no longer exist
|
||||
|
||||
Reference in New Issue
Block a user