-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add automatic cleanup scripts on worktree removal #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add support for cleanup-worktree scripts that run automatically when
removing a worktree with wt remove.
Changes:
- Add cleanup-worktree array support in worktrees.json
- Scripts execute automatically before worktree removal (with confirmation)
- Add --skip-cleanup (-s) option to bypass cleanup scripts
- Add --trust (-t) option for CI environments (no confirmation)
- Add runCleanupScriptsSecure() function to src/utils/setup.ts
- Update README with cleanup documentation
Example worktrees.json:
{
"setup-worktree": ["npm install"],
"cleanup-worktree": ["docker-compose down"]
}
📝 WalkthroughWalkthroughThis PR introduces cleanup script execution for worktree removal. Users can define cleanup-worktree commands in worktrees.json that execute before worktree removal with optional confirmation. Two new CLI flags (--skip-cleanup, --trust) control cleanup behavior. Documentation, CLI configuration, and two new utility functions (loadCleanupCommands, runCleanupScriptsSecure) support the feature. Changes
Sequence DiagramsequenceDiagram
participant User
participant RemoveCmd as Remove Command
participant CleanupUtil as Cleanup Utility
participant Worktree as Git Worktree
User->>RemoveCmd: remove [path] [--skip-cleanup] [--trust]
alt skip-cleanup not set
RemoveCmd->>CleanupUtil: loadCleanupCommands(repoRoot)
CleanupUtil-->>RemoveCmd: cleanup commands + filePath
alt trust not set
RemoveCmd->>User: Confirm cleanup execution?
User-->>RemoveCmd: Yes/No
end
RemoveCmd->>CleanupUtil: Execute cleanup commands in worktree
CleanupUtil->>Worktree: Run each cleanup command
CleanupUtil-->>RemoveCmd: Cleanup complete (with error handling)
end
RemoveCmd->>Worktree: git worktree remove [path]
Worktree-->>RemoveCmd: Worktree removed
RemoveCmd-->>User: Success
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧹 Recent nitpick comments
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (7)
🧰 Additional context used📓 Path-based instructions (3)src/index.ts📄 CodeRabbit inference engine (.cursor/rules/project.mdc)
Files:
src/commands/remove.ts📄 CodeRabbit inference engine (.cursor/rules/project.mdc)
Files:
src/commands/*.ts📄 CodeRabbit inference engine (.cursor/rules/project.mdc)
Files:
🧠 Learnings (6)📓 Common learnings📚 Learning: 2025-08-04T13:02:29.847ZApplied to files:
📚 Learning: 2025-08-04T13:02:29.847ZApplied to files:
📚 Learning: 2025-08-04T13:02:29.847ZApplied to files:
📚 Learning: 2025-08-04T14:22:29.156ZApplied to files:
📚 Learning: 2025-08-04T13:02:29.847ZApplied to files:
🧬 Code graph analysis (3)build/commands/remove.js (1)
src/utils/setup.ts (3)
src/commands/remove.ts (1)
🔇 Additional comments (9)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Add support for
cleanup-worktreescripts that run automatically when removing a worktree withwt remove.Summary
cleanup-worktreearray support inworktrees.jsonfor automatic cleanup before worktree removalwt remove--skip-cleanup(-s) option to bypass cleanup scripts--trust(-t) option for CI environments (no confirmation)runCleanupScriptsSecure()function to src/utils/setup.tssrc/utils/scripts.ts(removes code duplication from setup.ts)setup-worktree(dangerous commands blocked)READMEwith cleanup documentationExample worktrees.json
{ "setup-worktree": ["npm install"], "cleanup-worktree": ["docker-compose down", "rm -rf node_modules"] }Usage
wt remove my-branch # Runs cleanup scripts, then removes worktree
wt remove my-branch -s # Skips cleanup scripts
wt remove my-branch --force # Force removal (for untracked files)
Test plan
[x]
wt setupstill executessetup-worktreescripts correctly[x]
wt removeexecutescleanup-worktreescripts before removal[x]
wt remove --skip-cleanupbypasses cleanup scripts[x]
wt remove --forceworks with untracked files[x] Security filters block dangerous commands in cleanup scripts
[x]
pnpm buildcompiles without errorsSummary by CodeRabbit
Release Notes
New Features
removecommand:-s, --skip-cleanup: Skip cleanup script execution.-t, --trust: Run cleanup without user confirmation (ideal for CI/CD environments).Documentation
✏️ Tip: You can customize this high-level summary in your review settings.