Repository navigation
feat!: point bare template vars to Active worktree identity - #1660
Merged
Merged
Conversation
BREAKING: `worktree_path` now points to the Active worktree (the subject of the operation), not always the execution directory. Changes: - **pre-switch (existing)**: `worktree_path` now points to the destination worktree, not the source. Use `base_worktree_path` or `cwd` for the source. - **pre-switch (create)**: `worktree_path` points to the planned path. `commit`/`short_commit` are absent (branch has no HEAD yet). - **post-merge**: `worktree_path` now points to the feature worktree (Active), not the target. Use `target_worktree_path` or `cwd` for where code landed. Feature commit is captured before removal. The "Active = subject" model: - Arriving ops (switch, create): Active = destination - Departing ops (merge, remove): Active = source Empty extra_vars now remove the key from the template context, producing a clear "undefined variable" error instead of silently returning a stale value. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
approved these changes
Mar 22, 2026
worktrunk-bot
left a comment
Collaborator
There was a problem hiding this comment.
Minor: removed_commit (merge.rs:311-313) runs rev-parse HEAD on the current worktree, but feature_commit (line 271-275) already captured the same value — HEAD hasn't changed between the two calls. removed_commit could reuse feature_commit.clone() to avoid the redundant git invocation. This is outside the diff, so happy to push a fix commit if you'd like.
Co-Authored-By: Claude <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Mar 22, 2026
Follow-up fixes and documentation for the template variable redesign (#1655, #1660). **Code fixes:** - `commit` derivation now uses `rev-parse <branch>` instead of `rev-parse HEAD`, so `{{ commit }}` follows the Active branch - `base` / `base_worktree_path` now available in post-switch for existing switches (previously only creates) - post-remove `{{ target }}` now correctly resolves to the destination branch, not the removed branch **Documentation:** - Restructured template variable table — Active vars grouped first, directional vars second, repo-level vars last - Added arrive/depart table explaining what bare vars, `base`, and `target` point to per operation - Documented when `cwd` differs from `worktree_path` (pre-switch existing, post-remove, post-merge with removal) **Tests:** 4 new integration tests for directional var semantics. Ref #1633 > _This was written by Claude Code on behalf of @max-sixty_ Co-authored-by: Claude <[email protected]>
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 2 of the template variable redesign. Breaking change:
worktree_pathnow points to the Active worktree (the subject of the operation) rather than always the execution directory.Changes
pre-switch (existing worktrees):
worktree_pathnow points to the destination worktree, not the source. Usebase_worktree_pathorcwdfor the source.pre-switch (creates):
worktree_pathkeeps its default (source worktree = cwd). The planned destination path isn't available until after pre-switch hooks complete.post-merge:
worktree_pathnow points to the feature worktree (Active), not the merge target. Usetarget_worktree_pathorcwdfor where code landed. Feature identity (path, name, commit) is captured before removal so it's available even after the worktree is deleted.Empty extra_vars removal mechanism removed — it was added and then removed in the same PR as the pre-switch create approach changed.
The model
Mnemonic: "Are you going there, or is it going away?"
Ref #1633