Skip to content

fix: use worktree root for hook CWD and template variables#1097

Merged
max-sixty merged 2 commits intomainfrom
hook-path
Feb 18, 2026
Merged

fix: use worktree root for hook CWD and template variables#1097
max-sixty merged 2 commits intomainfrom
hook-path

Conversation

@max-sixty
Copy link
Copy Markdown
Owner

Summary

  • CommandEnv used .path() (returns "." by default) instead of .root() (git rev-parse --show-toplevel) for worktree_path
  • When running from a subdirectory, hooks got the wrong CWD, {{ worktree_path }} resolved to ".", and {{ worktree_name }} resolved to "unknown"
  • Every other codepath in the project already uses .root() for this — CommandEnv was the outlier

Test plan

  • Added test_hook_template_variables_from_subdirectory — runs wt hook pre-merge from src/components/ subdirectory, verifies {{ worktree_path }} is absolute, {{ worktree_name }} is correct, and hook CWD is the worktree root
  • Verified test fails with old .path() code (hook writes files to subdirectory, not worktree root)
  • All 1206 tests pass (unit + integration + shell integration)

This was written by Claude Code on behalf of @max-sixty

CommandEnv used .path() (which returns "." or whatever base_path was set
to) instead of .root() (which runs `git rev-parse --show-toplevel`). When
running from a subdirectory, hooks got the wrong CWD and template
variables like {{ worktree_path }} resolved to "." instead of the
absolute worktree root.

Co-Authored-By: Claude <noreply@anthropic.com>
On Windows, to_posix_path() converts C:\... to /c/... for Git Bash
compatibility. Path::is_absolute() rejects this POSIX-style path on
Windows. Use assert_ne!(".", ...) instead — what matters is that the
path is not relative.

Co-Authored-By: Claude <noreply@anthropic.com>
@max-sixty max-sixty merged commit ac2aaac into main Feb 18, 2026
22 checks passed
@max-sixty max-sixty deleted the hook-path branch February 18, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants