Skip to content

feat!: point bare template vars to Active worktree identity - #1660

Merged
max-sixty merged 2 commits into
mainfrom
template-vars
Mar 22, 2026
Merged

max-sixty merged 2 commits into
mainfrom
template-vars

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Phase 2 of the template variable redesign. Breaking change: worktree_path now points to the Active worktree (the subject of the operation) rather than always the execution directory.

Changes

pre-switch (existing worktrees): worktree_path now points to the destination worktree, not the source. Use base_worktree_path or cwd for the source.

pre-switch (creates): worktree_path keeps its default (source worktree = cwd). The planned destination path isn't available until after pre-switch hooks complete.

post-merge: worktree_path now points to the feature worktree (Active), not the merge target. Use target_worktree_path or cwd for 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

  • Arriving ops (switch, create): Active = destination
  • Departing ops (merge, remove): Active = source

Mnemonic: "Are you going there, or is it going away?"

Ref #1633

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

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 worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@max-sixty
max-sixty merged commit 3845969 into main Mar 22, 2026
22 checks passed
@max-sixty
max-sixty deleted the template-vars branch March 22, 2026 21:57
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]>
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