-
Notifications
You must be signed in to change notification settings - Fork 46
feat: add preRemove hooks #48
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
feat: add preRemove hooks #48
Conversation
Add gtr.hook.preRemove configuration for hooks that run before worktree deletion, allowing cleanup tasks that need directory access. Hook failures abort removal unless --force is used.
Add commented preRemove hook examples to both .gtrconfig.example and gtr.config.example template files.
Add gtr.hook.preRemove to tab completion for bash, zsh, and fish.
Add preRemove hook configuration examples and document hook execution order (preRemove runs before deletion, postRemove after). Note that --force bypasses hook failures.
Add preRemove hook to configuration reference, key mapping table, environment variables section, and manual testing checklist.
WalkthroughThis pull request implements pre-remove hooks ( Changes
Sequence DiagramsequenceDiagram
participant User
participant CLI as git gtr rm
participant Hooks as Hook System
participant FS as Filesystem
User->>CLI: git gtr rm worktree [--force]
CLI->>CLI: Validate worktree exists
CLI->>Hooks: Run preRemove hooks<br/>(REPO_ROOT, WORKTREE_PATH, BRANCH)
alt Hook Success or --force flag
Hooks-->>CLI: Hook(s) completed/skipped
CLI->>FS: Remove worktree directory
FS-->>CLI: Removal complete
CLI->>Hooks: Run postRemove hooks<br/>(notifications/logging)
Hooks-->>CLI: postRemove complete
CLI-->>User: Success
else Hook Failure (no --force)
Hooks-->>CLI: Non-zero exit code
CLI-->>User: Abort removal with error message
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (8)
🧰 Additional context used📓 Path-based instructions (8)completions/*📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
completions/{gtr.bash,_git-gtr,gtr.fish}📄 CodeRabbit inference engine (.github/instructions/completions.instructions.md)
Files:
completions/gtr.fish📄 CodeRabbit inference engine (.github/instructions/completions.instructions.md)
Files:
**/*.{bash,fish,sh}📄 CodeRabbit inference engine (.github/instructions/sh.instructions.md)
Files:
bin/gtr📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
{bin/gtr,lib/**/*.sh,adapters/**/*.sh}📄 CodeRabbit inference engine (.github/instructions/testing.instructions.md)
Files:
completions/_git-gtr📄 CodeRabbit inference engine (.github/instructions/completions.instructions.md)
Files:
completions/gtr.bash📄 CodeRabbit inference engine (.github/instructions/completions.instructions.md)
Files:
🪛 Shellcheck (0.11.0)completions/gtr.bash[warning] 71-71: Prefer mapfile or read -a to split command output (or quote to avoid splitting). (SC2207) 🔇 Additional comments (12)
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 |
|
good idea, lgtm |
Pull Request
Description
Add
gtr.hook.preRemoveconfiguration for hooks that run before worktree deletion, allowing cleanup tasks that need directory access (e.g., stopping services, saving state). Hooks run with cwd set to the worktree directory. Hook failures abort removal unless--forceis used.Motivation
Currently,
postRemovehooks run after the worktree is deleted, so they cannot access files in the worktree. Users need a way to run cleanup scripts before deletion.Fixes #47
Type of Change
Testing
Manual Testing Checklist
Tested on:
Core functionality tested:
git gtr new <branch>- Create worktreegit gtr go <branch>- Navigate to worktreegit gtr editor <branch>- Open in editor (if applicable)git gtr ai <branch>- Start AI tool (if applicable)git gtr rm <branch>- Remove worktreegit gtr list- List worktreesgit gtr config- Configuration commands (if applicable)Test Steps
git gtr config add gtr.hook.preRemove "echo 'Running cleanup'"git gtr new test-preremovegit gtr rm test-preremoveExpected behavior: Hook runs before worktree is deleted, with cwd in the worktree directory.
Actual behavior: Hook runs before worktree is deleted, with cwd in the worktree directory.
Additional tests:
--forceflag bypasses hook failure (verified)Breaking Changes
Checklist
Before submitting this PR, please check:
git gtr(production) and./bin/gtr(development)Additional Context
Hook execution order for
git gtr rm:preRemovehooks run (cwd = worktree directory)postRemovehooks run (cwd = repo root)License Acknowledgment
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache License 2.0.
Summary by CodeRabbit
New Features
--forceis used.Documentation
✏️ Tip: You can customize this high-level summary in your review settings.