feat: add postCd hook for shell integration (#108)#109
Conversation
Introduce a new postCd hook that allows users to run commands in the current shell after executing 'gtr cd'. This feature enhances shell integration by enabling environment variable modifications and script sourcing. Update documentation and completions to reflect this addition.
WalkthroughA new post-cd hook feature executes user-defined commands after Changes
Sequence DiagramsequenceDiagram
participant Shell as Shell Integration
participant GitConfig as Git Config
participant RepoConfig as .gtrconfig File
participant HookMgr as Hook Manager
participant Eval as Eval Executor
Shell->>GitConfig: Read gtr.hook.postCd
Shell->>RepoConfig: Read hooks.postCd
HookMgr->>HookMgr: Merge & Deduplicate hooks
HookMgr->>HookMgr: Export WORKTREE_PATH, REPO_ROOT, BRANCH
HookMgr->>Eval: Eval each hook command
Eval-->>Shell: Return exit status / errors
HookMgr->>HookMgr: Unset WORKTREE_PATH, REPO_ROOT, BRANCH
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@docs/configuration.md`:
- Around line 309-312: MD028 is triggered by a blank line inside a single
blockquote; remove the empty line between the two Note blockquote lines so they
remain in the same contiguous blockquote (i.e., merge the two quoted Note lines
into one continuous blockquote without blank lines) so the two lines: "**Note:**
Pre-remove hooks..." and "**Note:** `postCd` hooks..." are part of the same
blockquote and comply with markdownlint.
Clarify the behavior of postCd hooks in the documentation, emphasizing that they run in the current shell and can modify environment variables. This update enhances user understanding of the feature's functionality.
Summary
Adds a new
gtr.hook.postCdhook that runs commands in the user's current shell aftergtr cdchanges directory. Closes #108.sourcefiles, set env vars, and modify shell stategit config(gtr.hook.postCd) and.gtrconfig(hooks.postCd), with deduplicationREPO_ROOT,WORKTREE_PATH, andBRANCHenv vars (consistent with other hooks)cdExample use cases:
Changes
bin/gtr— postCd hook logic in bash/zsh/fish shell wrappers + help textlib/config.sh— forward and reverse key mapping forgtr.hook.postCd↔hooks.postCdcompletions/— all three completion files updated withgtr.hook.postCddocs/configuration.md— hook table and notes updatedREADME.md— quick-start example addedtemplates/.gtrconfig.example— commented example addedTest plan
eval "$(./bin/gtr init bash)"thengtr cd <branch>— verify postCd hooks firegtr.hook.postCdviagit config --add— verify it runs after cdhooks.postCdin.gtrconfig— verify it runs after cdREPO_ROOT,WORKTREE_PATH,BRANCHenv vars are set during hook executiongit gtr config listshows postCd hooksgtr.hook.postCdin all three shellsSummary by CodeRabbit
gtr cdcompletes, enabling environment setup and variable sourcing. Configure viagtr.hook.postCdglobally or per-repo. Hooks receive environment context and failures warn without affecting the directory change.