Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Refactor: Use Jinja2-style template variables

Maximilian Roos50cfc30f24c6
diff --git a/.claude-plugin/skills/worktrunk/reference/hook-types-reference.md b/.claude-plugin/skills/worktrunk/reference/hook-types-reference.md
index f4f45ec4a..5d449fef4 100644
--- a/.claude-plugin/skills/worktrunk/reference/hook-types-reference.md
+++ b/.claude-plugin/skills/worktrunk/reference/hook-types-reference.md
@@ -12,8 +12,8 @@ Detailed behavior and use cases for all five Worktrunk hook types.
| `pre-merge-command` | Before merging to target | Yes | Yes | Basic + Merge | Sequential |
| `post-merge-command` | After successful merge | Yes | No | Basic + Merge | Sequential |
-**Basic variables**: `{repo}`, `{branch}`, `{worktree}`, `{repo_root}`
-**Merge variables**: Basic + `{target}`
+**Basic variables**: `{{ repo }}`, `{{ branch }}`, `{{ worktree }}`, `{{ repo_root }}`
+**Merge variables**: Basic + `{{ target }}`
## Detailed Behavior
@@ -206,25 +206,25 @@ Behavior same as array format, but with descriptive names.
### Basic Variables (All Hooks)
```toml
-post-create-command = "echo 'Working on {branch} in {repo}'"
+post-create-command = "echo 'Working on {{ branch }} in {{ repo }}'"
```
Available:
-- `{repo}` - Repository name (e.g., "my-project")
-- `{branch}` - Branch name (e.g., "feature-auth")
-- `{worktree}` - Absolute path to worktree
-- `{repo_root}` - Absolute path to repository root
+- `{{ repo }}` - Repository name (e.g., "my-project")
+- `{{ branch }}` - Branch name (e.g., "feature-auth")
+- `{{ worktree }}` - Absolute path to worktree
+- `{{ repo_root }}` - Absolute path to repository root
### Merge Variables (Merge Hooks Only)
```toml
-pre-merge-command = "echo 'Merging {branch} into {target}'"
+pre-merge-command = "echo 'Merging {{ branch }} into {{ target }}'"
```
Available in: `pre-commit-command`, `pre-merge-command`, `post-merge-command`
Additional variable:
-- `{target}` - Target branch for merge (e.g., "main")
+- `{{ target }}` - Target branch for merge (e.g., "main")
### Conditional Logic
@@ -232,9 +232,9 @@ Use shell conditionals with variables:
```toml
pre-merge-command = """
-if [ "{target}" = "main" ]; then
+if [ "{{ target }}" = "main" ]; then
npm run test:full
-elif [ "{target}" = "staging" ]; then
+elif [ "{{ target }}" = "staging" ]; then
npm run test:integration
else
npm run test:unit
@@ -265,9 +265,9 @@ pre-merge-command = ["npm test", "npm run build"]
### Target-Specific Behavior
```toml
post-merge-command = """
-if [ "{target}" = "main" ]; then
+if [ "{{ target }}" = "main" ]; then
npm run deploy:production
-elif [ "{target}" = "staging" ]; then
+elif [ "{{ target }}" = "staging" ]; then
npm run deploy:staging
fi
"""
diff --git a/.claude-plugin/skills/worktrunk/reference/project-config.md b/.claude-plugin/skills/worktrunk/reference/project-config.md
index 67813ae61..de47cd907 100644
--- a/.claude-plugin/skills/worktrunk/reference/project-config.md
+++ b/.claude-plugin/skills/worktrunk/reference/project-config.md
@@ -186,15 +186,15 @@ All hooks support template variables for dynamic behavior.
### Basic Variables (All Hooks)
Available in all hook types:
-- `{repo}` - Repository name (e.g., "my-project")
-- `{branch}` - Branch name (e.g., "feature-auth")
-- `{worktree}` - Absolute path to worktree
-- `{repo_root}` - Absolute path to repository root
+- `{{ repo }}` - Repository name (e.g., "my-project")
+- `{{ branch }}` - Branch name (e.g., "feature-auth")
+- `{{ worktree }}` - Absolute path to worktree
+- `{{ repo_root }}` - Absolute path to repository root
<example type="basic-variables">
```toml
-post-create-command = "echo 'Working on {branch} in {repo}'"
+post-create-command = "echo 'Working on {{ branch }} in {{ repo }}'"
```
</example>
@@ -204,14 +204,14 @@ post-create-command = "echo 'Working on {branch} in {repo}'"
Available in: `pre-commit-command`, `pre-merge-command`, `post-merge-command`
Additional variable:
-- `{target}` - Target branch for merge (e.g., "main")
+- `{{ target }}` - Target branch for merge (e.g., "main")
<example type="conditional-with-variables">
Run different tests based on target branch:
```toml
pre-merge-command = """
-if [ "{target}" = "main" ]; then
+if [ "{{ target }}" = "main" ]; then
npm run test:full
else
npm run test:quick
diff --git a/.claude-plugin/skills/worktrunk/reference/user-config.md b/.claude-plugin/skills/worktrunk/reference/user-config.md
index ba02320c2..cf4c246f7 100644
--- a/.claude-plugin/skills/worktrunk/reference/user-config.md
+++ b/.claude-plugin/skills/worktrunk/reference/user-config.md
@@ -107,19 +107,19 @@ Users may want different worktree organization patterns.
Default (parent siblings):
```toml
-worktree-path = "../{main-worktree}.{branch}"
+worktree-path = "../{{ main_worktree }}.{{ branch }}"
```
Result: `~/code/myproject` → `~/code/myproject.feature-auth`
Inside repo:
```toml
-worktree-path = ".worktrees/{branch}"
+worktree-path = ".worktrees/{{ branch }}"
```
Result: `~/code/myproject/.worktrees/feature-auth`
Shared directory:
```toml
-worktree-path = "../worktrees/{main-worktree}/{branch}"
+worktree-path = "../worktrees/{{ main_worktree }}/{{ branch }}"
```
Result: `~/code/worktrees/myproject/feature-auth`
@@ -135,8 +135,8 @@ Result: `~/code/worktrees/myproject/feature-auth`
### Available Variables
-- `{main-worktree}` - Main worktree directory name
-- `{branch}` - Branch name (slashes replaced with dashes)
+- `{{ main_worktree }}` - Main worktree directory name
+- `{{ branch }}` - Branch name (slashes replaced with dashes)
### Validation Rules
@@ -206,7 +206,7 @@ Complete reference:
```toml
# Worktree Path Template
-worktree-path = "../{main-worktree}.{branch}"
+worktree-path = "../{{ main_worktree }}.{{ branch }}"
# LLM Commit Generation (Optional)
[commit-generation]
diff --git a/.config/wt.example.toml b/.config/wt.example.toml
index 7264e3d22..638857c58 100644
--- a/.config/wt.example.toml
+++ b/.config/wt.example.toml
@@ -6,13 +6,13 @@
# developers working on the project.
# Available template variables (all commands):
-# {repo} - Repository name (e.g., "my-project")
-# {branch} - Branch name (slashes replaced with dashes)
-# {worktree} - Absolute path to the worktree
-# {repo_root} - Absolute path to the repository root
+# {{ repo }} - Repository name (e.g., "my-project")
+# {{ branch }} - Branch name (slashes replaced with dashes)
+# {{ worktree }} - Absolute path to the worktree
+# {{ repo_root }} - Absolute path to the repository root
#
# Merge-related commands also support:
-# {target} - Target branch for the merge (e.g., "main")
+# {{ target }} - Target branch for the merge (e.g., "main")
# Post-Create Commands
# Runs SEQUENTIALLY and BLOCKS until complete
diff --git a/.config/wt.toml b/.config/wt.toml
index f35477b96..d595eef84 100644
--- a/.config/wt.toml
+++ b/.config/wt.toml
@@ -2,24 +2,24 @@
# These run after creating a new worktree
#
# Available template variables:
-# {repo} - Repository name (e.g., "worktrunk.project-config")
-# {branch} - Branch name with slashes replaced by dashes
-# {worktree} - Path to the new worktree
-# {repo_root} - Path to the main repository root
+# {{ repo }} - Repository name (e.g., "worktrunk.project-config")
+# {{ branch }} - Branch name with slashes replaced by dashes
+# {{ worktree }} - Path to the new worktree
+# {{ repo_root }} - Path to the main repository root
# Seed target/ from base worktree using CoW (copy-on-write)
# Each worktree gets its own target/ (avoids incremental build corruption)
# but seeded from base to warm-start builds (low disk usage)
# macOS: uses cp -c (clonefile on APFS)
# Linux: would need cp --reflink=auto (GNU coreutils) or rsync 3.2.3+ with --reflink
post-start-command = """
-[ -d {repo_root}/target ] &&
-[ ! -e {worktree}/target ] &&
-cp -cR {repo_root}/target/. {worktree}/target/
+[ -d {{ repo_root }}/target ] &&
+[ ! -e {{ worktree }}/target ] &&
+cp -cR {{ repo_root }}/target/. {{ worktree }}/target/
"""
# Post-merge commands
# These run in the main worktree after successful merge and push
-# Available template variables: {repo}, {branch}, {worktree}, {repo_root}, {target}
+# Available template variables: {{ repo }}, {{ branch }}, {{ worktree }}, {{ repo_root }}, {{ target }}
post-merge-command = "cargo install --path ."
# Pre-commit commands
diff --git a/README.md b/README.md
index a224f5f2a..14b90bb3d 100644
--- a/README.md
+++ b/README.md
@@ -303,7 +303,7 @@ $ wt merge
| **pre-merge-command** | After rebase completes during `wt merge` (validates rebased state before push) | Sequential, blocking, fail-fast | Terminates merge immediately |
| **post-merge-command** | After successful merge and push to target branch, before cleanup | Sequential, blocking | Logs warning, continues with remaining commands |
-**Template variables:** `{repo}`, `{branch}`, `{worktree}`, `{repo_root}`, `{target}`
+**Template variables:** `{{ repo }}`, `{{ branch }}`, `{{ worktree }}`, `{{ repo_root }}`, `{{ target }}`
**Skipping hooks:** `wt switch --no-verify` or `wt merge --no-verify`
@@ -403,7 +403,7 @@ wt config help # Show LLM setup guide
Global config at `~/.config/worktrunk/config.toml`:
```toml
-worktree-path = "../{main-worktree}.{branch}"
+worktree-path = "../{{ main_worktree }}.{{ branch }}"
[commit-generation]
command = "llm"
@@ -412,7 +412,7 @@ args = ["-m", "claude-haiku-4-5-20251001"]
Project config at `.config/wt.toml` in the repository root (see Project Hooks above).
-Worktree path defaults: `../repo.branch/` (siblings to main repo). Variables: `{main-worktree}`, `{branch}`, `{repo}`.
+Worktree path defaults: `../repo.branch/` (siblings to main repo). Variables: `{{ main_worktree }}`, `{{ branch }}`, `{{ repo }}`.
</details>
@@ -526,10 +526,10 @@ Customize the pattern in `~/.config/worktrunk/config.toml`:
```toml
# Inside the repo (keeps everything contained)
-worktree-path = ".worktrees/{branch}"
+worktree-path = ".worktrees/{{ branch }}"
# Shared directory with multiple repos
-worktree-path = "../worktrees/{main-worktree}/{branch}"
+worktree-path = "../worktrees/{{ main_worktree }}/{{ branch }}"
```
### Shell Integration
diff --git a/config.example.toml b/config.example.toml
index 1352d9d25..41b36956a 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -6,16 +6,16 @@
# Generate with: wt config init
# Worktree Path Template
-# Variables: {main-worktree} = main worktree directory name, {branch} = branch name
+# Variables: {{ main_worktree }} = main worktree directory name, {{ branch }} = branch name
# Branch slashes are replaced with dashes (feature/auth → feature-auth)
# Paths are relative to the main worktree root (original repository directory)
-worktree-path = "../{main-worktree}.{branch}"
+worktree-path = "../{{ main_worktree }}.{{ branch }}"
# Alternative: Inside repo (useful for bare repos)
-# worktree-path = ".worktrees/{branch}"
+# worktree-path = ".worktrees/{{ branch }}"
# Alternative: Shared directory for multiple repos
-# worktree-path = "../worktrees/{main-worktree}/{branch}"
+# worktree-path = "../worktrees/{{ main_worktree }}/{{ branch }}"
# Commit Message Generation (Optional)
# For generating commit messages during merge operations (wt merge)
diff --git a/src/cli.rs b/src/cli.rs
index b00497a86..769168c63 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -274,7 +274,7 @@ Switching to Existing Worktree:
Creating New Worktree (--create):
1. Creates new branch (defaults to current default branch as base)
- 2. Creates worktree in configured location (default: ../{main-worktree}.{branch})
+ 2. Creates worktree in configured location (default: ../{{ main_worktree }}.{{ branch }})
3. Runs post-create hooks sequentially (blocking)
4. Shows success message
5. Spawns post-start hooks in background (non-blocking)
@@ -427,7 +427,7 @@ The merge operation follows a strict order designed for fail-fast execution:
5. Run pre-merge commands
Runs commands from project config's [pre-merge-command] after rebase completes.
- These receive {target} placeholder for the target branch. Commands run sequentially
+ These receive {{ target }} placeholder for the target branch. Commands run sequentially
and any failure aborts the merge immediately. Skip with --no-verify.
6. Push to target
diff --git a/src/commands/command_executor.rs b/src/commands/command_executor.rs
index 71452e6c2..39f36f5fe 100644
--- a/src/commands/command_executor.rs
+++ b/src/commands/command_executor.rs
@@ -82,7 +82,13 @@ fn expand_commands(
.map(|(k, v)| (k.as_str(), v.as_str()))
.collect();
- let expanded_str = expand_template(&cmd.template, repo_name, ctx.branch, &extras_ref);
+ let expanded_str = expand_template(&cmd.template, repo_name, ctx.branch, &extras_ref)
+ .map_err(|e| {
+ GitError::message(format!(
+ "Failed to expand command template '{}': {}",
+ cmd.template, e
+ ))
+ })?;
expanded_commands.push(Command::with_expansion(
cmd.name.clone(),
cmd.template.clone(),
diff --git a/src/commands/worktree.rs b/src/commands/worktree.rs
index 5801d1f34..2aa0564bf 100644
--- a/src/commands/worktree.rs
+++ b/src/commands/worktree.rs
@@ -231,7 +231,11 @@ pub fn handle_switch(
.to_str()
.ok_or_else(|| GitError::message("Invalid UTF-8 in path"))?;
- let worktree_path = repo_root.join(config.format_path(repo_name, &resolved_branch));
+ let worktree_path = repo_root.join(
+ config
+ .format_path(repo_name, &resolved_branch)
+ .map_err(|e| GitError::message(format!("Failed to format worktree path: {}", e)))?,
+ );
// Create the worktree
// Build git worktree add command
diff --git a/src/config/commands.rs b/src/config/commands.rs
index f44aa2d95..0ce91920c 100644
--- a/src/config/commands.rs
+++ b/src/config/commands.rs
@@ -15,7 +15,7 @@ pub type CommandPhase = HookType;
pub struct Command {
/// Optional name for the command (e.g., "build", "test", or auto-numbered "1", "2")
pub name: Option<String>,
- /// Template string that may contain variables like {branch}, {worktree}
+ /// Template string that may contain variables like {{ branch }}, {{ worktree }}
pub template: String,
/// Expanded command with variables substituted (same as template if not expanded yet)
pub expanded: String,
diff --git a/src/config/expansion.rs b/src/config/expansion.rs
index c9a1186d3..cd75cc26c 100644
--- a/src/config/expansion.rs
+++ b/src/config/expansion.rs
@@ -1,30 +1,41 @@
//! Template expansion utilities for worktrunk
//!
-//! Provides functions for expanding template variables in paths and commands with
-//! proper shell escaping to prevent injection vulnerabilities.
+//! Uses minijinja for all template rendering with automatic shell escaping.
+//! All templates support Jinja2 syntax including filters, conditionals, and loops.
-/// Expand template variables in a string
+use minijinja::Environment;
+
+/// Expand template variables using minijinja
///
/// All templates support:
-/// - `{main-worktree}` - Main worktree directory name
-/// - `{branch}` - Branch name (sanitized: slashes → dashes)
+/// - `{{ main_worktree }}` - Main worktree directory name
+/// - `{{ branch }}` - Branch name (sanitized: slashes → dashes)
+/// - `{{ repo }}` - Repository name (alias for main_worktree for consistency)
///
/// Additional variables can be provided via the `extra` parameter.
///
+/// Variables are automatically shell-escaped for safe use in commands.
+/// Use the `|e` or `|escape` filter for additional escaping if needed.
+///
/// # Examples
/// ```
/// use worktrunk::config::expand_template;
/// use std::collections::HashMap;
///
-/// let result = expand_template("path/{main-worktree}/{branch}", "myrepo", "feature/foo", &HashMap::new());
+/// // Simple variable substitution
+/// let result = expand_template("path/{{ main_worktree }}/{{ branch }}", "myrepo", "feature/foo", &HashMap::new()).unwrap();
/// assert_eq!(result, "path/myrepo/feature-foo");
+///
+/// // Using conditionals
+/// let result = expand_template("{% if branch == 'main' %}production{% else %}development{% endif %}", "myrepo", "main", &HashMap::new()).unwrap();
+/// assert_eq!(result, "production");
/// ```
pub fn expand_template(
template: &str,
main_worktree: &str,
branch: &str,
extra: &std::collections::HashMap<&str, &str>,
-) -> String {
+) -> Result<String, String> {
use shell_escape::escape;
use std::borrow::Cow;
@@ -32,32 +43,57 @@ pub fn expand_template(
let safe_branch = branch.replace(['/', '\\'], "-");
// Shell-escape all variables to prevent issues with spaces and special characters
- let escaped_worktree = escape(Cow::Borrowed(main_worktree));
- let escaped_branch = escape(Cow::Borrowed(safe_branch.as_str()));
-
- let mut result = template
- .replace("{main-worktree}", &escaped_worktree)
- .replace("{branch}", &escaped_branch);
+ let escaped_worktree = escape(Cow::Borrowed(main_worktree)).to_string();
+ let escaped_branch = escape(Cow::Borrowed(safe_branch.as_str())).to_string();
- // Apply any extra variables (also escaped)
+ // Collect all escaped extra variables (must be owned to satisfy lifetimes)
+ let mut extra_escaped = Vec::new();
for (key, value) in extra {
- let escaped_value = escape(Cow::Borrowed(*value));
- result = result.replace(&format!("{{{}}}", key), &escaped_value);
+ let escaped_value = escape(Cow::Borrowed(*value)).to_string();
+ let key_normalized = key.replace('-', "_");
+ extra_escaped.push((key_normalized, escaped_value));
}
- result
+ // Build context map with String keys (required by minijinja)
+ let mut context_map = std::collections::BTreeMap::new();
+ context_map.insert(
+ "main_worktree".to_string(),
+ minijinja::Value::from(escaped_worktree.as_str()),
+ );
+ context_map.insert(
+ "branch".to_string(),
+ minijinja::Value::from(escaped_branch.as_str()),
+ );
+ context_map.insert(
+ "repo".to_string(),
+ minijinja::Value::from(escaped_worktree.as_str()),
+ );
+ for (key, value) in &extra_escaped {
+ context_map.insert(key.clone(), minijinja::Value::from(value.as_str()));
+ }
+
+ // Render template with minijinja
+ let mut env = Environment::new();
+ // Preserve trailing newlines in templates (important for multiline shell commands)
+ env.set_keep_trailing_newline(true);
+ let tmpl = env
+ .template_from_str(template)
+ .map_err(|e| format!("Template syntax error: {}", e))?;
+
+ tmpl.render(minijinja::Value::from_object(context_map))
+ .map_err(|e| format!("Template render error: {}", e))
}
-/// Expand command template variables
+/// Expand command template variables using minijinja
///
/// Convenience function for expanding command templates with common variables.
///
/// Supported variables:
-/// - `{repo}` - Repository name
-/// - `{branch}` - Branch name (sanitized)
-/// - `{worktree}` - Path to the worktree
-/// - `{repo_root}` - Path to the main repository root
-/// - `{target}` - Target branch (for merge commands, optional)
+/// - `{{ repo }}` - Repository name
+/// - `{{ branch }}` - Branch name (sanitized: slashes → dashes)
+/// - `{{ worktree }}` - Path to the worktree
+/// - `{{ repo_root }}` - Path to the main repository root
+/// - `{{ target }}` - Target branch (for merge commands, optional)
///
/// # Examples
/// ```
@@ -65,13 +101,13 @@ pub fn expand_template(
/// use std::path::Path;
///
/// let cmd = expand_command_template(
-/// "cp {repo_root}/target {worktree}/target",
+/// "cp {{ repo_root }}/target {{ worktree }}/target",
/// "myrepo",
/// "feature",
/// Path::new("/path/to/worktree"),
/// Path::new("/path/to/repo"),
/// None,
-/// );
+/// ).unwrap();
/// ```
pub fn expand_command_template(
command: &str,
@@ -80,7 +116,7 @@ pub fn expand_command_template(
worktree_path: &std::path::Path,
repo_root: &std::path::Path,
target_branch: Option<&str>,
-) -> String {
+) -> Result<String, String> {
let mut extra = std::collections::HashMap::new();
let worktree_str = worktree_path.to_string_lossy();
let repo_root_str = repo_root.to_string_lossy();
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 9124bfe60..b30a0179b 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -58,14 +58,14 @@ mod tests {
let config = WorktrunkConfig::default();
let toml = toml::to_string(&config).unwrap();
assert!(toml.contains("worktree-path"));
- assert!(toml.contains("../{main-worktree}.{branch}"));
+ assert!(toml.contains("../{{ main_worktree }}.{{ branch }}"));
assert!(toml.contains("commit-generation"));
}
#[test]
fn test_default_config() {
let config = WorktrunkConfig::default();
- assert_eq!(config.worktree_path, "../{main-worktree}.{branch}");
+ assert_eq!(config.worktree_path, "../{{ main_worktree }}.{{ branch }}");
assert_eq!(config.commit_generation.command, None);
assert!(config.projects.is_empty());
}
@@ -73,12 +73,12 @@ mod tests {
#[test]
fn test_format_worktree_path() {
let config = WorktrunkConfig {
- worktree_path: "{main-worktree}.{branch}".to_string(),
+ worktree_path: "{{ main_worktree }}.{{ branch }}".to_string(),
commit_generation: CommitGenerationConfig::default(),
projects: std::collections::BTreeMap::new(),
};
assert_eq!(
- config.format_path("myproject", "feature-x"),
+ config.format_path("myproject", "feature-x").unwrap(),
"myproject.feature-x"
);
}
@@ -86,12 +86,12 @@ mod tests {
#[test]
fn test_format_worktree_path_custom_template() {
let config = WorktrunkConfig {
- worktree_path: "{main-worktree}-{branch}".to_string(),
+ worktree_path: "{{ main_worktree }}-{{ branch }}".to_string(),
commit_generation: CommitGenerationConfig::default(),
projects: std::collections::BTreeMap::new(),
};
assert_eq!(
- config.format_path("myproject", "feature-x"),
+ config.format_path("myproject", "feature-x").unwrap(),
"myproject-feature-x"
);
}
@@ -99,12 +99,12 @@ mod tests {
#[test]
fn test_format_worktree_path_only_branch() {
let config = WorktrunkConfig {
- worktree_path: ".worktrees/{main-worktree}/{branch}".to_string(),
+ worktree_path: ".worktrees/{{ main_worktree }}/{{ branch }}".to_string(),
commit_generation: CommitGenerationConfig::default(),
projects: std::collections::BTreeMap::new(),
};
assert_eq!(
- config.format_path("myproject", "feature-x"),
+ config.format_path("myproject", "feature-x").unwrap(),
".worktrees/myproject/feature-x"
);
}
@@ -113,12 +113,12 @@ mod tests {
fn test_format_worktree_path_with_slashes() {
// Slashes should be replaced with dashes to prevent directory traversal
let config = WorktrunkConfig {
- worktree_path: "{main-worktree}.{branch}".to_string(),
+ worktree_path: "{{ main_worktree }}.{{ branch }}".to_string(),
commit_generation: CommitGenerationConfig::default(),
projects: std::collections::BTreeMap::new(),
};
assert_eq!(
- config.format_path("myproject", "feature/foo"),
+ config.format_path("myproject", "feature/foo").unwrap(),
"myproject.feature-foo"
);
}
@@ -126,12 +126,12 @@ mod tests {
#[test]
fn test_format_worktree_path_with_multiple_slashes() {
let config = WorktrunkConfig {
- worktree_path: ".worktrees/{main-worktree}/{branch}".to_string(),
+ worktree_path: ".worktrees/{{ main_worktree }}/{{ branch }}".to_string(),
commit_generation: CommitGenerationConfig::default(),
projects: std::collections::BTreeMap::new(),
};
assert_eq!(
- config.format_path("myproject", "feature/sub/task"),
+ config.format_path("myproject", "feature/sub/task").unwrap(),
".worktrees/myproject/feature-sub-task"
);
}
@@ -140,12 +140,12 @@ mod tests {
fn test_format_worktree_path_with_backslashes() {
// Windows-style path separators should also be sanitized
let config = WorktrunkConfig {
- worktree_path: ".worktrees/{main-worktree}/{branch}".to_string(),
+ worktree_path: ".worktrees/{{ main_worktree }}/{{ branch }}".to_string(),
commit_generation: CommitGenerationConfig::default(),
projects: std::collections::BTreeMap::new(),
};
assert_eq!(
- config.format_path("myproject", "feature\\foo"),
+ config.format_path("myproject", "feature\\foo").unwrap(),
".worktrees/myproject/feature-foo"
);
}
@@ -607,11 +607,12 @@ task2 = "echo 'Task 2 running' > task2.txt"
use std::collections::HashMap;
let result = expand_template(
- "../{main-worktree}.{branch}",
+ "../{{ main_worktree }}.{{ branch }}",
"myrepo",
"feature-x",
&HashMap::new(),
- );
+ )
+ .unwrap();
assert_eq!(result, "../myrepo.feature-x");
}
@@ -620,19 +621,21 @@ task2 = "echo 'Task 2 running' > task2.txt"
use std::collections::HashMap;
let result = expand_template(
- "{main-worktree}/{branch}",
+ "{{ main_worktree }}/{{ branch }}",
"myrepo",
"feature/foo",
&HashMap::new(),
- );
+ )
+ .unwrap();
assert_eq!(result, "myrepo/feature-foo");
let result = expand_template(
- ".worktrees/{main-worktree}/{branch}",
+ ".worktrees/{{ main_worktree }}/{{ branch }}",
"myrepo",
"feat\\bar",
&HashMap::new(),
- );
+ )
+ .unwrap();
assert_eq!(result, ".worktrees/myrepo/feat-bar");
}
@@ -645,11 +648,12 @@ task2 = "echo 'Task 2 running' > task2.txt"
extra.insert("repo_root", "/path/to/repo");
let result = expand_template(
- "{repo_root}/target -> {worktree}/target",
+ "{{ repo_root }}/target -> {{ worktree }}/target",
"myrepo",
"main",
&extra,
- );
+ )
+ .unwrap();
assert_eq!(result, "/path/to/repo/target -> /path/to/worktree/target");
}
@@ -657,7 +661,7 @@ task2 = "echo 'Task 2 running' > task2.txt"
fn test_commit_generation_config_mutually_exclusive_validation() {
// Test that deserialization rejects both template and template-file
let toml_content = r#"
-worktree-path = "../{main-worktree}.{branch}"
+worktree-path = "../{{ main_worktree }}.{{ branch }}"
[commit-generation]
command = "llm"
@@ -685,7 +689,7 @@ template-file = "~/file.txt"
fn test_squash_template_mutually_exclusive_validation() {
// Test that deserialization rejects both squash-template and squash-template-file
let toml_content = r#"
-worktree-path = "../{main-worktree}.{branch}"
+worktree-path = "../{{ main_worktree }}.{{ branch }}"
[commit-generation]
command = "llm"
diff --git a/src/config/project.rs b/src/config/project.rs
index 30fde6b54..2435a359c 100644
--- a/src/config/project.rs
+++ b/src/config/project.rs
@@ -16,26 +16,26 @@ use super::commands::CommandConfig;
/// # Template Variables
///
/// All commands support these template variables:
-/// - `{repo}` - Repository name (e.g., "my-project")
-/// - `{branch}` - Branch name (e.g., "feature-foo")
-/// - `{worktree}` - Absolute path to the worktree
-/// - `{repo_root}` - Absolute path to the repository root
+/// - `{{ repo }}` - Repository name (e.g., "my-project")
+/// - `{{ branch }}` - Branch name (e.g., "feature-foo")
+/// - `{{ worktree }}` - Absolute path to the worktree
+/// - `{{ repo_root }}` - Absolute path to the repository root
///
/// Merge-related commands (`pre-commit-command`, `pre-merge-command`, `post-merge-command`) also support:
-/// - `{target}` - Target branch for the merge (e.g., "main")
+/// - `{{ target }}` - Target branch for the merge (e.g., "main")
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
pub struct ProjectConfig {
/// Commands to execute sequentially before worktree is ready (blocking)
/// Supports string (single command), array (sequential), or table (named, sequential)
///
- /// Available template variables: `{repo}`, `{branch}`, `{worktree}`, `{repo_root}`
+ /// Available template variables: `{{ repo }}`, `{{ branch }}`, `{{ worktree }}`, `{{ repo_root }}`
#[serde(default, rename = "post-create-command")]
pub post_create_command: Option<CommandConfig>,
/// Commands to execute in parallel as background processes (non-blocking)
/// Supports string (single), array (parallel), or table (named, parallel)
///
- /// Available template variables: `{repo}`, `{branch}`, `{worktree}`, `{repo_root}`
+ /// Available template variables: `{{ repo }}`, `{{ branch }}`, `{{ worktree }}`, `{{ repo_root }}`
#[serde(default, rename = "post-start-command")]
pub post_start_command: Option<CommandConfig>,
@@ -44,7 +44,7 @@ pub struct ProjectConfig {
/// All commands must exit with code 0 for commit to proceed
/// Runs before any commit operation during `wt merge` (both squash and no-squash modes)
///
- /// Available template variables: `{repo}`, `{branch}`, `{worktree}`, `{repo_root}`, `{target}`
+ /// Available template variables: `{{ repo }}`, `{{ branch }}`, `{{ worktree }}`, `{{ repo_root }}`, `{{ target }}`
#[serde(default, rename = "pre-commit-command")]
pub pre_commit_command: Option<CommandConfig>,
@@ -52,7 +52,7 @@ pub struct ProjectConfig {
/// Supports string (single command), array (sequential), or table (named, sequential)
/// All commands must exit with code 0 for merge to proceed
///
- /// Available template variables: `{repo}`, `{branch}`, `{worktree}`, `{repo_root}`, `{target}`
+ /// Available template variables: `{{ repo }}`, `{{ branch }}`, `{{ worktree }}`, `{{ repo_root }}`, `{{ target }}`
#[serde(default, rename = "pre-merge-command")]
pub pre_merge_command: Option<CommandConfig>,
@@ -60,7 +60,7 @@ pub struct ProjectConfig {
/// Supports string (single command), array (sequential), or table (named, sequential)
/// Runs after push succeeds but before cleanup
///
- /// Available template variables: `{repo}`, `{branch}`, `{worktree}`, `{repo_root}`, `{target}`
+ /// Available template variables: `{{ repo }}`, `{{ branch }}`, `{{ worktree }}`, `{{ repo_root }}`, `{{ target }}`
#[serde(default, rename = "post-merge-command")]
pub post_merge_command: Option<CommandConfig>,
}
diff --git a/src/config/snapshots/worktrunk__config__test__snapshot_complex_templates.snap b/src/config/snapshots/worktrunk__config__test__snapshot_complex_templates.snap
index 5c0bbaddb..754f5de4f 100644
--- a/src/config/snapshots/worktrunk__config__test__snapshot_complex_templates.snap
+++ b/src/config/snapshots/worktrunk__config__test__snapshot_complex_templates.snap
@@ -3,14 +3,14 @@ source: src/config/test.rs
expression: results
---
- - cd_and_merge
- - "cd {worktree} && git merge {target}"
+ - "cd {{ worktree }} && git merge {{ target }}"
- feature branch
- "cd '/path with spaces/wt' && git merge 'main; rm -rf /'"
- - npm_install
- - "cd {main-worktree}/{branch} && npm install"
+ - "cd {{ main_worktree }}/{{ branch }} && npm install"
- feature/new-ui
- cd /repo/path/feature-new-ui && npm install
- - echo_vars
- - "echo 'Branch: {branch}' 'Worktree: {worktree}'"
+ - "echo 'Branch: {{ branch }}' 'Worktree: {{ worktree }}'"
- test$injection
- "echo 'Branch: 'test$injection'' 'Worktree: '/path with spaces/wt''"
diff --git a/src/config/test.rs b/src/config/test.rs
index 425fadc8f..bb49b5bc0 100644
--- a/src/config/test.rs
+++ b/src/config/test.rs
@@ -10,11 +10,12 @@ use std::collections::HashMap;
fn test_expand_template_normal() {
let extras = HashMap::new();
let result = expand_template(
- "echo {branch} {main-worktree}",
+ "echo {{ branch }} {{ main_worktree }}",
"myrepo",
"feature",
&extras,
- );
+ )
+ .unwrap();
assert_eq!(result, "echo feature myrepo");
}
@@ -22,7 +23,13 @@ fn test_expand_template_normal() {
fn test_expand_template_branch_with_slashes() {
// Bug hypothesis: Branch names with slashes are sanitized to dashes
let extras = HashMap::new();
- let result = expand_template("echo {branch}", "myrepo", "feature/nested/branch", &extras);
+ let result = expand_template(
+ "echo {{ branch }}",
+ "myrepo",
+ "feature/nested/branch",
+ &extras,
+ )
+ .unwrap();
// Line 459: safe_branch = branch.replace(['/', '\\'], "-")
assert_eq!(result, "echo feature-nested-branch");
@@ -34,7 +41,7 @@ fn test_expand_template_branch_with_slashes() {
fn test_expand_template_branch_with_spaces() {
// Branch names with spaces are shell-escaped
let extras = HashMap::new();
- let result = expand_template("echo {branch}", "myrepo", "feature name", &extras);
+ let result = expand_template("echo {{ branch }}", "myrepo", "feature name", &extras).unwrap();
// Shell-escaped with single quotes
assert_eq!(result, "echo 'feature name'");
@@ -45,7 +52,8 @@ fn test_expand_template_branch_with_spaces() {
fn test_expand_template_branch_with_special_shell_chars() {
// Special shell characters are escaped
let extras = HashMap::new();
- let result = expand_template("echo {branch}", "myrepo", "feature$(whoami)", &extras);
+ let result =
+ expand_template("echo {{ branch }}", "myrepo", "feature$(whoami)", &extras).unwrap();
// Shell-escaped, prevents command substitution
assert_eq!(result, "echo 'feature$(whoami)'");
@@ -57,7 +65,7 @@ fn test_expand_template_branch_with_special_shell_chars() {
fn test_expand_template_branch_with_backticks() {
// Backticks are escaped
let extras = HashMap::new();
- let result = expand_template("echo {branch}", "myrepo", "feature`id`", &extras);
+ let result = expand_template("echo {{ branch }}", "myrepo", "feature`id`", &extras).unwrap();
assert_eq!(result, "echo 'feature`id`'");
}
@@ -67,7 +75,7 @@ fn test_expand_template_branch_with_backticks() {
fn test_expand_template_branch_with_quotes() {
// Quotes are shell-escaped to prevent injection
let extras = HashMap::new();
- let result = expand_template("echo '{branch}'", "myrepo", "feature'test", &extras);
+ let result = expand_template("echo '{{ branch }}'", "myrepo", "feature'test", &extras).unwrap();
// Shell escapes single quotes as '\''
assert_eq!(result, "echo ''feature'\\''test''");
@@ -79,7 +87,7 @@ fn test_expand_template_extra_vars_with_spaces() {
// Extra variables with spaces are shell-escaped
let mut extras = HashMap::new();
extras.insert("worktree", "/path with spaces/to/worktree");
- let result = expand_template("cd {worktree}", "myrepo", "main", &extras);
+ let result = expand_template("cd {{ worktree }}", "myrepo", "main", &extras).unwrap();
assert_eq!(result, "cd '/path with spaces/to/worktree'");
}
@@ -90,7 +98,7 @@ fn test_expand_template_extra_vars_with_dollar_sign() {
// Dollar signs are shell-escaped to prevent variable expansion
let mut extras = HashMap::new();
extras.insert("worktree", "/path/$USER/worktree");
- let result = expand_template("cd {worktree}", "myrepo", "main", &extras);
+ let result = expand_template("cd {{ worktree }}", "myrepo", "main", &extras).unwrap();
assert_eq!(result, "cd '/path/$USER/worktree'");
// Shell-escaped, prevents $USER from being expanded
@@ -102,7 +110,7 @@ fn test_expand_template_extra_vars_with_command_substitution() {
// Special shell characters are shell-escaped to prevent injection
let mut extras = HashMap::new();
extras.insert("target", "main; rm -rf /");
- let result = expand_template("git merge {target}", "myrepo", "feature", &extras);
+ let result = expand_template("git merge {{ target }}", "myrepo", "feature", &extras).unwrap();
assert_eq!(result, "git merge 'main; rm -rf /'");
// Shell-escaped, prevents semicolon from being executed as command separator
@@ -110,46 +118,47 @@ fn test_expand_template_extra_vars_with_command_substitution() {
#[test]
fn test_expand_template_variable_collision() {
- // BUG HYPOTHESIS: What if extra vars contain "branch" or "main-worktree"?
- // Looking at code: base replacements happen first (line 461-463), then extra vars (line 466-468)
- // So extra var "branch" won't override {branch}, but could create unexpected results
+ // What if extra vars contain "branch"? With minijinja, extra vars added later override built-ins
let mut extras = HashMap::new();
extras.insert("branch", "hacked");
- let result = expand_template("echo {branch}", "myrepo", "feature", &extras);
+ let result = expand_template("echo {{ branch }}", "myrepo", "feature", &extras).unwrap();
- // {branch} is replaced with "feature" first (line 463)
- // Then {branch} is replaced again? No, already done!
- assert_eq!(result, "echo feature");
+ // Extra vars are added to context after built-ins, so they override
+ assert_eq!(result, "echo hacked");
}
#[test]
fn test_expand_template_extra_var_named_branch() {
- // What if we have both {branch} in template and "branch" in extras?
+ // What if we have both {{ branch }} in template and "branch" in extras?
let mut extras = HashMap::new();
extras.insert("branch", "extra-branch");
- let result = expand_template("echo {branch} from {branch}", "myrepo", "main", &extras);
+ let result = expand_template(
+ "echo {{ branch }} from {{ branch }}",
+ "myrepo",
+ "main",
+ &extras,
+ )
+ .unwrap();
- // Both {branch} occurrences should be replaced with "main" (the branch parameter)
- // Extra var "branch" doesn't affect it because format is "{{{}}}", so looks for "{branch}"
- // and "branch" creates different search patterns
- assert_eq!(result, "echo main from main");
+ // Extra vars override built-ins, so both occurrences use "extra-branch"
+ assert_eq!(result, "echo extra-branch from extra-branch");
}
#[test]
fn test_expand_template_missing_variable() {
// What happens with undefined variables?
let extras = HashMap::new();
- let result = expand_template("echo {undefined}", "myrepo", "main", &extras);
+ let result = expand_template("echo {{ undefined }}", "myrepo", "main", &extras).unwrap();
- // No replacement, left as-is
- assert_eq!(result, "echo {undefined}");
+ // minijinja will render undefined variables as empty string
+ assert_eq!(result, "echo ");
}
#[test]
#[cfg(unix)]
fn test_expand_template_empty_branch() {
let extras = HashMap::new();
- let result = expand_template("echo {branch}", "myrepo", "", &extras);
+ let result = expand_template("echo {{ branch }}", "myrepo", "", &extras).unwrap();
// Empty string is shell-escaped to ''
assert_eq!(result, "echo ''");
@@ -160,7 +169,7 @@ fn test_expand_template_empty_branch() {
fn test_expand_template_unicode_in_branch() {
// Unicode characters in branch name are shell-escaped
let extras = HashMap::new();
- let result = expand_template("echo {branch}", "myrepo", "feature-🚀", &extras);
+ let result = expand_template("echo {{ branch }}", "myrepo", "feature-🚀", &extras).unwrap();
// Unicode is preserved but quoted for shell safety
assert_eq!(result, "echo 'feature-🚀'");
@@ -170,7 +179,8 @@ fn test_expand_template_unicode_in_branch() {
fn test_expand_template_backslash_in_branch() {
// Windows-style path separators
let extras = HashMap::new();
- let result = expand_template("echo {branch}", "myrepo", "feature\\branch", &extras);
+ let result =
+ expand_template("echo {{ branch }}", "myrepo", "feature\\branch", &extras).unwrap();
// Line 459: backslashes also replaced with dashes
assert_eq!(result, "echo feature-branch");
@@ -183,11 +193,12 @@ fn test_expand_template_multiple_replacements() {
extras.insert("target", "develop");
let result = expand_template(
- "cd {worktree} && git merge {target} from {branch}",
+ "cd {{ worktree }} && git merge {{ target }} from {{ branch }}",
"myrepo",
"feature",
&extras,
- );
+ )
+ .unwrap();
assert_eq!(result, "cd /path/to/wt && git merge develop from feature");
}
@@ -196,20 +207,19 @@ fn test_expand_template_multiple_replacements() {
fn test_expand_template_curly_braces_without_variables() {
// Just curly braces, not variables
let extras = HashMap::new();
- let result = expand_template("echo {}", "myrepo", "main", &extras);
+ let result = expand_template("echo {}", "myrepo", "main", &extras).unwrap();
assert_eq!(result, "echo {}");
}
#[test]
fn test_expand_template_nested_curly_braces() {
- // Nested braces (shouldn't match variable pattern)
+ // Nested braces - minijinja doesn't support {{{ syntax, use literal curly braces instead
let extras = HashMap::new();
- let result = expand_template("echo {{branch}}", "myrepo", "main", &extras);
+ let result =
+ expand_template("echo {{ '{' ~ branch ~ '}' }}", "myrepo", "main", &extras).unwrap();
- // Only {branch} inside gets replaced, outer braces remain
- // Wait, let's think: replace("{branch}", "main") on "{{branch}}"
- // Results in "{main}"
+ // Renders as {main}
assert_eq!(result, "echo {main}");
}
@@ -241,7 +251,7 @@ fn snapshot_shell_escaping_special_chars() {
let mut results = Vec::new();
for (name, branch) in test_cases {
- let result = expand_template("echo {branch}", "myrepo", branch, &extras);
+ let result = expand_template("echo {{ branch }}", "myrepo", branch, &extras).unwrap();
results.push((name, branch, result));
}
@@ -263,7 +273,7 @@ fn snapshot_shell_escaping_quotes() {
let mut results = Vec::new();
for (name, branch) in test_cases {
- let result = expand_template("echo {branch}", "myrepo", branch, &extras);
+ let result = expand_template("echo {{ branch }}", "myrepo", branch, &extras).unwrap();
results.push((name, branch, result));
}
@@ -288,7 +298,13 @@ fn snapshot_shell_escaping_paths() {
for (name, path) in test_cases {
extras.clear();
extras.insert("worktree", path);
- let result = expand_template("cd {worktree} && echo {branch}", "myrepo", "main", &extras);
+ let result = expand_template(
+ "cd {{ worktree }} && echo {{ branch }}",
+ "myrepo",
+ "main",
+ &extras,
+ )
+ .unwrap();
results.push((name, path, result));
}
@@ -306,24 +322,24 @@ fn snapshot_complex_templates() {
let test_cases = vec![
(
"cd_and_merge",
- "cd {worktree} && git merge {target}",
+ "cd {{ worktree }} && git merge {{ target }}",
"feature branch",
),
(
"npm_install",
- "cd {main-worktree}/{branch} && npm install",
+ "cd {{ main_worktree }}/{{ branch }} && npm install",
"feature/new-ui",
),
(
"echo_vars",
- "echo 'Branch: {branch}' 'Worktree: {worktree}'",
+ "echo 'Branch: {{ branch }}' 'Worktree: {{ worktree }}'",
"test$injection",
),
];
let mut results = Vec::new();
for (name, template, branch) in test_cases {
- let result = expand_template(template, "/repo/path", branch, &extras);
+ let result = expand_template(template, "/repo/path", branch, &extras).unwrap();
results.push((name, template, branch, result));
}
diff --git a/src/config/user.rs b/src/config/user.rs
index 770d8684e..c5f320eab 100644
--- a/src/config/user.rs
+++ b/src/config/user.rs
@@ -18,20 +18,20 @@ use super::expansion::expand_template;
///
/// The `worktree-path` template is relative to the repository root.
/// Supported variables:
-/// - `{main-worktree}` - Main worktree directory name
-/// - `{branch}` - Branch name (slashes replaced with dashes)
+/// - `{{ main_worktree }}` - Main worktree directory name
+/// - `{{ branch }}` - Branch name (slashes replaced with dashes)
///
/// # Examples
///
/// ```toml
/// # Default - parent directory siblings
-/// worktree-path = "../{main-worktree}.{branch}"
+/// worktree-path = "../{{ main_worktree }}.{{ branch }}"
///
/// # Inside repo (clean, no redundant directory)
-/// worktree-path = ".worktrees/{branch}"
+/// worktree-path = ".worktrees/{{ branch }}"
///
/// # Repository-namespaced (useful for shared directories with multiple repos)
-/// worktree-path = "../worktrees/{main-worktree}/{branch}"
+/// worktree-path = "../worktrees/{{ main_worktree }}/{{ branch }}"
///
/// # Commit generation configuration
/// [commit-generation]
@@ -135,7 +135,7 @@ pub struct UserProjectConfig {
impl Default for WorktrunkConfig {
fn default() -> Self {
Self {
- worktree_path: "../{main-worktree}.{branch}".to_string(),
+ worktree_path: "../{{ main_worktree }}.{{ branch }}".to_string(),
commit_generation: CommitGenerationConfig::default(),
projects: std::collections::BTreeMap::new(),
}
@@ -205,18 +205,18 @@ impl WorktrunkConfig {
/// Format a worktree path using this configuration's template.
///
/// # Arguments
- /// * `main_worktree` - Main worktree directory name (replaces {main-worktree} in template)
- /// * `branch` - Branch name (replaces {branch} in template, slashes sanitized to dashes)
+ /// * `main_worktree` - Main worktree directory name (replaces {{ main_worktree }} in template)
+ /// * `branch` - Branch name (replaces {{ branch }} in template, slashes sanitized to dashes)
///
/// # Examples
/// ```
/// use worktrunk::config::WorktrunkConfig;
///
/// let config = WorktrunkConfig::default();
- /// let path = config.format_path("myproject", "feature/foo");
+ /// let path = config.format_path("myproject", "feature/foo").unwrap();
/// assert_eq!(path, "../myproject.feature-foo");
/// ```
- pub fn format_path(&self, main_worktree: &str, branch: &str) -> String {
+ pub fn format_path(&self, main_worktree: &str, branch: &str) -> Result<String, String> {
expand_template(
&self.worktree_path,
main_worktree,
diff --git a/src/styling/mod.rs b/src/styling/mod.rs
index cc90e3f07..a4c893a16 100644
--- a/src/styling/mod.rs
+++ b/src/styling/mod.rs
@@ -45,7 +45,7 @@ mod tests {
#[test]
fn test_toml_formatting() {
- let toml_content = r#"worktree-path = "../{repo}.{branch}"
+ let toml_content = r#"worktree-path = "../{{ repo }}.{{ branch }}"
[llm]
args = []
diff --git a/tests/integration_tests/approval_save.rs b/tests/integration_tests/approval_save.rs
index 3173e6b7f..a607c72e5 100644
--- a/tests/integration_tests/approval_save.rs
+++ b/tests/integration_tests/approval_save.rs
@@ -33,7 +33,7 @@ fn test_approval_saves_to_disk() {
// Verify TOML structure
let toml_content = fs::read_to_string(&config_path).unwrap();
assert_snapshot!(toml_content, @r#"
- worktree-path = "../{main-worktree}.{branch}"
+ worktree-path = "../{{ main_worktree }}.{{ branch }}"
[commit-generation]
args = []
@@ -87,7 +87,7 @@ fn test_duplicate_approvals_not_saved_twice() {
// Verify file contains only one entry
let toml_content = fs::read_to_string(&config_path).unwrap();
assert_snapshot!(toml_content, @r#"
- worktree-path = "../{main-worktree}.{branch}"
+ worktree-path = "../{{ main_worktree }}.{{ branch }}"
[commit-generation]
args = []
@@ -137,7 +137,7 @@ fn test_multiple_project_approvals() {
// Verify file structure
let toml_content = fs::read_to_string(&config_path).unwrap();
assert_snapshot!(toml_content, @r#"
- worktree-path = "../{main-worktree}.{branch}"
+ worktree-path = "../{{ main_worktree }}.{{ branch }}"
[commit-generation]
args = []
@@ -224,7 +224,7 @@ fn test_force_flag_does_not_save_approval() {
// Load the config and verify it's still empty (no approvals added)
let saved_config = fs::read_to_string(&config_path).unwrap();
assert_snapshot!(saved_config, @r#"
- worktree-path = "../{main-worktree}.{branch}"
+ worktree-path = "../{{ main_worktree }}.{{ branch }}"
[commit-generation]
args = []
@@ -260,7 +260,7 @@ fn test_force_flag_saves_to_new_config_file() {
// Verify content
let content = fs::read_to_string(&config_path).unwrap();
assert_snapshot!(content, @r#"
- worktree-path = "../{main-worktree}.{branch}"
+ worktree-path = "../{{ main_worktree }}.{{ branch }}"
[commit-generation]
args = []
diff --git a/tests/integration_tests/approval_ui.rs b/tests/integration_tests/approval_ui.rs
index 2f2cdb7b6..5c2a216c2 100644
--- a/tests/integration_tests/approval_ui.rs
+++ b/tests/integration_tests/approval_ui.rs
@@ -47,7 +47,7 @@ fn test_approval_single_command() {
let repo = TestRepo::new();
repo.commit("Initial commit");
- repo.write_project_config(r#"post-create-command = "echo 'Worktree path: {worktree}'""#);
+ repo.write_project_config(r#"post-create-command = "echo 'Worktree path: {{ worktree }}'""#);
repo.commit("Add config");
@@ -66,10 +66,10 @@ fn test_approval_multiple_commands() {
repo.write_project_config(
r#"post-create-command = [
- "echo 'Branch: {branch}'",
- "echo 'Worktree: {worktree}'",
- "echo 'Repo: {main-worktree}'",
- "cd {worktree} && pwd"
+ "echo 'Branch: {{ branch }}'",
+ "echo 'Worktree: {{ worktree }}'",
+ "echo 'Repo: {{ main_worktree }}'",
+ "cd {{ worktree }} && pwd"
]"#,
);
diff --git a/tests/integration_tests/bare_repository.rs b/tests/integration_tests/bare_repository.rs
index 8bf144a1e..edeaa7fd8 100644
--- a/tests/integration_tests/bare_repository.rs
+++ b/tests/integration_tests/bare_repository.rs
@@ -207,7 +207,7 @@ fn test_bare_repo_switch_creates_worktree() {
// Create worktrunk config to use worktree naming pattern suitable for bare repos
let config = r#"
-worktree-path = "{branch}"
+worktree-path = "{{ branch }}"
"#;
fs::write(test.config_path(), config).expect("Failed to write config");
@@ -245,7 +245,7 @@ worktree-path = "{branch}"
);
// Verify the new worktree was created
- // With template "{branch}", it creates as sibling: bare-repo-name.feature
+ // With template "{{ branch }}", it creates as sibling: bare-repo-name.feature
let bare_name = test.bare_repo_path().file_name().unwrap().to_str().unwrap();
let expected_path = test.temp_path().join(format!("{}.feature", bare_name));
assert!(
@@ -282,7 +282,7 @@ fn test_bare_repo_switch_with_default_naming() {
test.commit_in_worktree(&main_worktree, "Initial commit");
// Use default naming pattern (should still work with bare repos)
- // Default is "../{main-worktree}.{branch}" which becomes "test-repo.git.feature"
+ // Default is "../{{ main_worktree }}.{{ branch }}" which becomes "test-repo.git.feature"
let mut cmd = wt_command();
test.configure_wt_cmd(&mut cmd);
cmd.args(["switch", "--create", "feature", "--internal"])
@@ -379,7 +379,7 @@ fn test_bare_repo_worktree_base_used_for_paths() {
// Configure to use simple branch naming
let config = r#"
-worktree-path = "{branch}"
+worktree-path = "{{ branch }}"
"#;
fs::write(test.config_path(), config).expect("Failed to write config");
@@ -424,7 +424,7 @@ fn test_bare_repo_equivalent_to_normal_repo() {
// Configure both with same worktree path pattern
let config = r#"
-worktree-path = "{branch}"
+worktree-path = "{{ branch }}"
"#;
fs::write(bare_test.config_path(), config).expect("Failed to write bare config");
fs::write(normal_test.test_config_path(), config).expect("Failed to write normal config");
diff --git a/tests/integration_tests/config_list.rs b/tests/integration_tests/config_list.rs
index dc928c502..9c56ffea5 100644
--- a/tests/integration_tests/config_list.rs
+++ b/tests/integration_tests/config_list.rs
@@ -15,7 +15,7 @@ fn test_config_list_with_project_config() {
fs::create_dir_all(&global_config_dir).unwrap();
fs::write(
global_config_dir.join("config.toml"),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[[approved-commands]]
project = "test-project"
@@ -57,7 +57,7 @@ server = "npm run dev"
exit_code: 0
----- stdout -----
⚪ Global Config: [TEMP_HOME]/.config/worktrunk/config.toml
-   worktree-path = "../{main-worktree}.{branch}"
+   worktree-path = "../{{ main_worktree }}.{{ branch }}"
 
  [[approved-commands]]
  project = "test-project"
@@ -85,7 +85,7 @@ fn test_config_list_no_project_config() {
fs::create_dir_all(&global_config_dir).unwrap();
fs::write(
global_config_dir.join("config.toml"),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
"#,
)
.unwrap();
@@ -109,7 +109,7 @@ fn test_config_list_no_project_config() {
exit_code: 0
----- stdout -----
⚪ Global Config: [TEMP_HOME]/.config/worktrunk/config.toml
-   worktree-path = "../{main-worktree}.{branch}"
+   worktree-path = "../{{ main_worktree }}.{{ branch }}"
⚪ Project Config: [REPO]/.config/wt.toml
💡 Not found
@@ -130,7 +130,7 @@ fn test_config_list_outside_git_repo() {
fs::create_dir_all(&global_config_dir).unwrap();
fs::write(
global_config_dir.join("config.toml"),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
"#,
)
.unwrap();
@@ -152,7 +152,7 @@ fn test_config_list_outside_git_repo() {
exit_code: 0
----- stdout -----
⚪ Global Config: [TEMP_HOME]/.config/worktrunk/config.toml
-   worktree-path = "../{main-worktree}.{branch}"
+   worktree-path = "../{{ main_worktree }}.{{ branch }}"
⚪ Project Config: Not in a git repository
diff --git a/tests/integration_tests/e2e_shell_post_start.rs b/tests/integration_tests/e2e_shell_post_start.rs
index edef7dc57..ae96c83b6 100644
--- a/tests/integration_tests/e2e_shell_post_start.rs
+++ b/tests/integration_tests/e2e_shell_post_start.rs
@@ -37,7 +37,7 @@ fn test_e2e_post_start_background_command(#[case] shell: &str) {
// Pre-approve the command
fs::write(
repo.test_config_path(),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = ["sleep 0.05 && echo 'Background task done' > bg_marker.txt"]
@@ -154,7 +154,7 @@ task2 = "sleep 0.05 && echo 'Task 2' > task2.txt"
// Pre-approve commands
fs::write(
repo.test_config_path(),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = [
@@ -226,7 +226,7 @@ fn test_bash_post_create_blocks() {
// Pre-approve command
fs::write(
repo.test_config_path(),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = ["echo 'Setup done' > setup.txt"]
@@ -300,7 +300,7 @@ fish_bg = "sleep 0.05 && echo 'Fish background done' > fish_bg.txt"
// Pre-approve command
fs::write(
repo.test_config_path(),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = ["sleep 0.05 && echo 'Fish background done' > fish_bg.txt"]
diff --git a/tests/integration_tests/internal_flag.rs b/tests/integration_tests/internal_flag.rs
index 90d481c9b..259dc5438 100644
--- a/tests/integration_tests/internal_flag.rs
+++ b/tests/integration_tests/internal_flag.rs
@@ -51,7 +51,7 @@ fn test_config_list_with_internal_flag() {
fs::create_dir_all(&global_config_dir).unwrap();
fs::write(
global_config_dir.join("config.toml"),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
"#,
)
.unwrap();
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rs
index 9c47ac55b..d0c9b3386 100644
--- a/tests/integration_tests/merge.rs
+++ b/tests/integration_tests/merge.rs
@@ -1167,7 +1167,7 @@ fn test_merge_post_merge_command_success() {
fs::create_dir_all(&config_dir).expect("Failed to create config dir");
fs::write(
config_dir.join("wt.toml"),
- r#"post-merge-command = "echo 'merged {branch} to {target}' > post-merge-ran.txt""#,
+ r#"post-merge-command = "echo 'merged {{ branch }} to {{ target }}' > post-merge-ran.txt""#,
)
.expect("Failed to write config");
@@ -1233,7 +1233,7 @@ fn test_merge_post_merge_command_skipped_with_no_verify() {
fs::create_dir_all(&config_dir).expect("Failed to create config dir");
fs::write(
config_dir.join("wt.toml"),
- r#"post-merge-command = "echo 'merged {branch} to {target}' > post-merge-ran.txt""#,
+ r#"post-merge-command = "echo 'merged {{ branch }} to {{ target }}' > post-merge-ran.txt""#,
)
.expect("Failed to write config");
@@ -1348,8 +1348,8 @@ fn test_merge_post_merge_command_named() {
config_dir.join("wt.toml"),
r#"
[post-merge-command]
-notify = "echo 'Merge to {target} complete' > notify.txt"
-deploy = "echo 'Deploying branch {branch}' > deploy.txt"
+notify = "echo 'Merge to {{ target }} complete' > notify.txt"
+deploy = "echo 'Deploying branch {{ branch }}' > deploy.txt"
"#,
)
.expect("Failed to write config");
diff --git a/tests/integration_tests/post_start_commands.rs b/tests/integration_tests/post_start_commands.rs
index 45e6fdfa8..57e893cf7 100644
--- a/tests/integration_tests/post_start_commands.rs
+++ b/tests/integration_tests/post_start_commands.rs
@@ -54,7 +54,7 @@ fn test_post_create_single_command() {
// Pre-approve the command by writing to the isolated test config
repo.write_test_config(
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = ["echo 'Setup complete'"]
@@ -81,7 +81,7 @@ fn test_post_create_multiple_commands_array() {
// Pre-approve both commands in temp HOME
repo.write_test_config(
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = [
@@ -116,7 +116,7 @@ setup = "echo 'Running setup'"
// Pre-approve both commands in temp HOME
repo.write_test_config(
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = [
@@ -146,7 +146,7 @@ fn test_post_create_failing_command() {
// Pre-approve the command in temp HOME
repo.write_test_config(
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = ["exit 1"]
@@ -169,10 +169,10 @@ fn test_post_create_template_expansion() {
// Create project config with template variables
repo.write_project_config(
r#"post-create-command = [
- "echo 'Repo: {main-worktree}' > info.txt",
- "echo 'Branch: {branch}' >> info.txt",
- "echo 'Worktree: {worktree}' >> info.txt",
- "echo 'Root: {repo_root}' >> info.txt"
+ "echo 'Repo: {{ main_worktree }}' > info.txt",
+ "echo 'Branch: {{ branch }}' >> info.txt",
+ "echo 'Worktree: {{ worktree }}' >> info.txt",
+ "echo 'Root: {{ repo_root }}' >> info.txt"
]"#,
);
@@ -181,14 +181,14 @@ fn test_post_create_template_expansion() {
// Pre-approve all commands in isolated test config
let repo_name = "test-repo";
repo.write_test_config(
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = [
- "echo 'Repo: {main-worktree}' > info.txt",
- "echo 'Branch: {branch}' >> info.txt",
- "echo 'Worktree: {worktree}' >> info.txt",
- "echo 'Root: {repo_root}' >> info.txt",
+ "echo 'Repo: {{ main_worktree }}' > info.txt",
+ "echo 'Branch: {{ branch }}' >> info.txt",
+ "echo 'Worktree: {{ worktree }}' >> info.txt",
+ "echo 'Root: {{ repo_root }}' >> info.txt",
]
"#,
);
@@ -246,7 +246,7 @@ fn test_post_start_single_background_command() {
// Pre-approve the command
repo.write_test_config(
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = ["sleep 0.1 && echo 'Background task done' > background.txt"]
@@ -294,7 +294,7 @@ task2 = "echo 'Task 2 running' > task2.txt"
// Pre-approve both commands
repo.write_test_config(
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = [
@@ -338,7 +338,7 @@ server = "sleep 0.05 && echo 'Server running' > server.txt"
// Pre-approve all commands
repo.write_test_config(
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = [
@@ -400,7 +400,7 @@ fn test_post_start_log_file_captures_output() {
// Pre-approve the command
repo.write_test_config(
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = ["echo 'stdout output' && echo 'stderr output' >&2"]
@@ -458,7 +458,7 @@ fn test_post_start_invalid_command_handling() {
// Pre-approve the command
repo.write_test_config(
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = ["echo 'unclosed quote"]
@@ -498,7 +498,7 @@ task3 = "echo 'TASK3_OUTPUT'"
// Pre-approve all commands
repo.write_test_config(
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = [
@@ -579,7 +579,7 @@ fn test_execute_flag_with_post_start_commands() {
// Pre-approve the command
repo.write_test_config(
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = ["echo 'Background task' > background.txt"]
@@ -630,7 +630,7 @@ fn test_post_start_complex_shell_commands() {
// Pre-approve the command
repo.write_test_config(
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = ["echo 'line1\nline2\nline3' | grep line2 > filtered.txt"]
@@ -677,7 +677,7 @@ echo 'second line' >> multiline.txt
echo 'third line' >> multiline.txt
";
repo.write_test_config(&format!(
- r#"worktree-path = "../{{main-worktree}}.{{branch}}"
+ r#"worktree-path = "../{{{{ main_worktree }}}}.{{{{ branch }}}}"
[projects."test-repo"]
approved-commands = ["""
@@ -738,7 +738,7 @@ else
fi
";
repo.write_test_config(&format!(
- r#"worktree-path = "../{{main-worktree}}.{{branch}}"
+ r#"worktree-path = "../{{{{ main_worktree }}}}.{{{{ branch }}}}"
[projects."test-repo"]
approved-commands = ["""
@@ -787,7 +787,7 @@ fn test_post_start_skipped_on_existing_worktree() {
// Pre-approve the command
repo.write_test_config(
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = ["echo 'POST-START-RAN' > post_start_marker.txt"]
diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rs
index 660d747df..9f1d490a0 100644
--- a/tests/integration_tests/shell_wrapper.rs
+++ b/tests/integration_tests/shell_wrapper.rs
@@ -653,7 +653,7 @@ watch = "echo 'Watching for file changes'"
// Pre-approve the commands in user config
fs::write(
repo.test_config_path(),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = [
@@ -732,7 +732,7 @@ test = "echo '✓ All 47 tests passed in 2.3s'"
// Pre-approve commands
fs::write(
repo.test_config_path(),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = [
@@ -813,7 +813,7 @@ test = "echo '✗ Test suite failed: 3 tests failing' && exit 1"
// Pre-approve the commands
fs::write(
repo.test_config_path(),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = [
@@ -902,7 +902,7 @@ check2 = "{} check2 3"
fs::write(
repo.test_config_path(),
format!(
- r#"worktree-path = "../{{main-worktree}}.{{branch}}"
+ r#"worktree-path = "../{{{{ main_worktree }}}}.{{{{ branch }}}}"
[projects."test-repo"]
approved-commands = [
@@ -957,7 +957,7 @@ approved-commands = [
// Pre-approve the command in user config
fs::write(
repo.test_config_path(),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = ["echo 'test command executed'"]
@@ -1059,7 +1059,7 @@ approved-commands = ["echo 'test command executed'"]
// Pre-approve the command in user config
fs::write(
repo.test_config_path(),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = ["echo 'background task'"]
@@ -1128,7 +1128,7 @@ approved-commands = ["echo 'background task'"]
// Pre-approve the command in user config
fs::write(
repo.test_config_path(),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ r#"worktree-path = "../{{ main_worktree }}.{{ branch }}"
[projects."test-repo"]
approved-commands = ["echo 'fish background task'"]
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snap
deleted file mode 100644
index 8979b77e1..000000000
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snap
+++ /dev/null
@@ -1,20 +0,0 @@
----
-source: tests/integration_tests/shell_wrapper.rs
-expression: output.normalized()
----
-🔄 Running post-create:
-  echo 'Installing dependencies...'
-
-Installing dependencies...
-
-🔄 Running post-create:
-  echo 'Building project...'
-
-Building project...
-
-✅ Created new worktree for feature-hooks from main: [TMPDIR]/test-repo.feature-hooks
-🔄 Running post-start server:
-  echo 'Starting dev server on port 3000'
-
-🔄 Running post-start watch:
-  echo 'Watching for file changes'
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index dad629b07..7dd0009fb 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -311,7 +311,7 @@ fn test_switch_no_config_commands_skips_post_start_commands() {
fs::write(
user_config_dir.join("config.toml"),
format!(
- r#"worktree-path = "../{{main-worktree}}.{{branch}}"
+ r#"worktree-path = "../{{{{ main_worktree }}}}.{{{{ branch }}}}"
[projects."main"]
approved-commands = ["{}"]
diff --git a/tests/snapshots/integration__integration_tests__internal_flag__config_list_with_internal_flag.snap b/tests/snapshots/integration__integration_tests__internal_flag__config_list_with_internal_flag.snap
index 22576093d..6f17c34c1 100644
--- a/tests/snapshots/integration__integration_tests__internal_flag__config_list_with_internal_flag.snap
+++ b/tests/snapshots/integration__integration_tests__internal_flag__config_list_with_internal_flag.snap
@@ -25,7 +25,7 @@ success: true
exit_code: 0
----- stdout -----
⚪ Global Config: [TEMP_HOME]/.config/worktrunk/config.toml
-  worktree-path = "../{main-worktree}.{branch}"
+  worktree-path = "../{{ main_worktree }}.{{ branch }}"
⚪ Project Config: [REPO]/.config/wt.toml
💡 Not found