fix(hook): declare fish target_dir variable outside if/else block to fix scoping#65
Conversation
WalkthroughThe changes refactor how the Fish shell script handles variable scoping for Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (2)**/*.go📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*_test.go📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (8)📓 Common learnings📚 Learning: 2025-12-02T13:33:48.693ZApplied to files:
📚 Learning: 2025-12-02T13:33:48.693ZApplied to files:
📚 Learning: 2025-12-02T13:33:48.693ZApplied to files:
📚 Learning: 2025-12-02T13:33:48.693ZApplied to files:
📚 Learning: 2025-12-02T13:33:48.693ZApplied to files:
📚 Learning: 2025-12-02T13:33:48.693ZApplied to files:
📚 Learning: 2025-12-02T13:33:48.693ZApplied to files:
🔇 Additional comments (3)
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 |
What
Fix fish shell variable scoping bug in
wtp cdhook that caused the command to fail silently.Why
The
wtp cd <worktree>command was not working in fish shell. Thetarget_dirvariable was always empty when checked outside the if/else block, causing the hook to fall through to the error handling path instead of changing directories.This bug was introduced in commit 3afdc10 (#64) when adding support for no-argument
wtp cd. The fish implementation incorrectly declaredtarget_dirwithset -linside the if/else blocks, but fish's block scoping means local variables declared inside a block are not accessible outside it.How
Declare the local variable before the if/else block, then assign to it (without
-l) inside the blocks:Testing
source (wtp shell-init fish | psub)
wtp cd # now works correctly
Breaking Changes
None. This is a bug fix that makes the existing wtp cd command work as documented in fish shell.
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.