Skip to content

Rename template variables for clarity with deprecation warnings - #369

Merged
max-sixty merged 8 commits into
mainfrom
path-name
Jan 2, 2026
Merged

max-sixty merged 8 commits into
mainfrom
path-name

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

  • Renames hook template variables for clearer semantics (repo_root → repo_path, worktree → worktree_path, main_worktree → repo)
  • Adds new main_worktree_path variable for the path to the default branch worktree
  • Shows deprecation warnings with migration assistance when old variables are used

Motivation

The old variable names were confusing:

  • worktree — is it a path or a name?
  • repo_root — repository root or main worktree?
  • main_worktree — sounds like a path, but it's actually the repo name

The new names use consistent conventions:

  • *_path suffix = absolute path
  • repo = repository directory name
  • main_worktree_path = path to default branch worktree (for sharing dependencies)

Deprecation behavior

When configs use deprecated variables:

▲ User config uses deprecated template variables: repo_root → repo_path, worktree → worktree_path
↳ Wrote migrated config.toml.new; to apply: mv ~/.config/worktrunk/config.toml.new ~/.config/worktrunk/config.toml
  • User config: Always shows warning
  • Project config: Only shows warning when in main worktree (where changes can be committed)
  • Warnings are deduplicated per path per process

Test plan

  • All 652 integration tests pass
  • Pre-commit lints pass
  • Verified warnings appear correctly from main vs linked worktrees
  • Verified migration file is created with correct replacements

🤖 Generated with Claude Code

@max-sixty
max-sixty force-pushed the path-name branch 10 times, most recently from 4c630f6 to 0287a86 Compare January 2, 2026 16:15
Renames hook template variables for clearer semantics:
- `repo_root` → `repo_path` (absolute path to repository root)
- `worktree` → `worktree_path` (absolute path to current worktree)
- `main_worktree` → `repo` (repository directory name)

Adds new `main_worktree_path` variable for the actual path to the default
branch worktree, useful for sharing dependencies across worktrees.

Deprecated variables continue to work but emit warnings with migration
assistance:
- Detects deprecated variables using minijinja's undeclared_variables()
- Creates a `.new` migration file with replacements
- Shows inline warning: "User config uses deprecated template variables:
  repo_root → repo_path, worktree → worktree_path"
- Shows hint: "Wrote migrated config.toml.new; to apply: mv ..."

Project config warnings only appear when in main worktree (where changes
can be committed). Warnings are deduplicated per path per process.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
max-sixty and others added 7 commits January 2, 2026 11:14
- Fix malformed template bug: check for closing `}}` BEFORE emitting
  replacement to prevent corrupted output
- Add shell escaping to mv command paths using shell_escape::escape
- Add `--` separator to mv command to prevent paths starting with `-`
  from being interpreted as flags
- Handle migration file write errors gracefully with hint message
  instead of propagating error that would block config loading
- Use distinct [TEST_CONFIG_NEW] placeholder for .new files in
  snapshots for better readability
- Add test for malformed template preservation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Replace manual character-by-character parsing (~55 lines) with regex-based
approach (~13 lines) that:
- Handles both {{ }} and {% %} Jinja blocks
- Supports multiline blocks with (?s) dotall mode
- Preserves original formatting instead of normalizing whitespace
- Uses word boundaries to avoid false matches

Trade-off: regex moves from dev to prod dependency.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Windows paths with backslashes get quoted by shell_escape, so the
filter needs to handle: 'C:\Users\...\test-config.toml'

Update regex to match both forward/backward slashes and optional quotes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Instead of regex-matching Jinja blocks, reuse extract_template_strings()
to get TOML string values, then do word-boundary replacement within them.

This naturally excludes TOML keys like `worktree-path` since we only
process string values, not keys.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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.

1 participant