Skip to content

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

Refactor: Rename `{repo}` to `{main-worktree}` in config

Maximilian Roos07c3965f09a1
diff --git a/config.example.toml b/config.example.toml
index 586985545..b9a1edca4 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -6,16 +6,16 @@
# Generate with: wt config init
# Worktree Path Template
-# Variables: {repo} = repository 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 = "../{repo}.{branch}"
+worktree-path = "../{main-worktree}.{branch}"
-# Alternative: Keep worktrees inside repo (useful for bare repos)
+# Alternative: Inside repo (useful for bare repos)
# worktree-path = ".worktrees/{branch}"
# Alternative: Shared directory for multiple repos
-# worktree-path = "../worktrees/{repo}/{branch}"
+# worktree-path = "../worktrees/{main-worktree}/{branch}"
# LLM Integration (Optional)
# For generating commit messages during merge operations (wt merge)
diff --git a/src/config.rs b/src/config.rs
index 60c15df4b..adf563da2 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -6,24 +6,22 @@ use toml;
/// Configuration for worktree path formatting and LLM integration.
///
-/// The `worktree-path` template is relative to the repository root and supports:
-/// - `{repo}` - Repository name
+/// 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)
///
/// # Examples
///
/// ```toml
/// # Default - parent directory siblings
-/// worktree-path = "../{repo}.{branch}"
+/// worktree-path = "../{main-worktree}.{branch}"
///
-/// # Inside repo (bare repository style)
-/// worktree-path = "{branch}"
-///
-/// # Organized in .worktrees subdirectory
+/// # Inside repo (clean, no redundant directory)
/// worktree-path = ".worktrees/{branch}"
///
-/// # Repository-namespaced shared directory (avoids conflicts)
-/// worktree-path = "../worktrees/{repo}/{branch}"
+/// # Repository-namespaced (useful for shared directories with multiple repos)
+/// worktree-path = "../worktrees/{main-worktree}/{branch}"
///
/// # LLM configuration for commit message generation
/// [llm]
@@ -123,7 +121,7 @@ pub struct ApprovedCommand {
impl Default for WorktrunkConfig {
fn default() -> Self {
Self {
- worktree_path: "../{repo}.{branch}".to_string(),
+ worktree_path: "../{main-worktree}.{branch}".to_string(),
llm: LlmConfig::default(),
approved_commands: Vec::new(),
}
@@ -163,7 +161,7 @@ impl WorktrunkConfig {
/// Format a worktree path using this configuration's template.
///
/// # Arguments
- /// * `repo` - Repository name (replaces {repo} in template)
+ /// * `main_worktree` - Main worktree directory name (replaces {main-worktree} in template)
/// * `branch` - Branch name (replaces {branch} in template, slashes sanitized to dashes)
///
/// # Examples
@@ -174,10 +172,10 @@ impl WorktrunkConfig {
/// let path = config.format_path("myproject", "feature/foo");
/// assert_eq!(path, "../myproject.feature-foo");
/// ```
- pub fn format_path(&self, repo: &str, branch: &str) -> String {
+ pub fn format_path(&self, main_worktree: &str, branch: &str) -> String {
expand_template(
&self.worktree_path,
- repo,
+ main_worktree,
branch,
&std::collections::HashMap::new(),
)
@@ -196,7 +194,7 @@ fn get_config_path() -> Option<PathBuf> {
/// Expand template variables in a string
///
/// All templates support:
-/// - `{repo}` - Repository name
+/// - `{main-worktree}` - Main worktree directory name
/// - `{branch}` - Branch name (sanitized: slashes → dashes)
///
/// Additional variables can be provided via the `extra` parameter.
@@ -206,12 +204,12 @@ fn get_config_path() -> Option<PathBuf> {
/// use worktrunk::config::expand_template;
/// use std::collections::HashMap;
///
-/// let result = expand_template("path/{repo}/{branch}", "myrepo", "feature/foo", &HashMap::new());
+/// let result = expand_template("path/{main-worktree}/{branch}", "myrepo", "feature/foo", &HashMap::new());
/// assert_eq!(result, "path/myrepo/feature-foo");
/// ```
pub fn expand_template(
template: &str,
- repo: &str,
+ main_worktree: &str,
branch: &str,
extra: &std::collections::HashMap<&str, &str>,
) -> String {
@@ -219,7 +217,7 @@ pub fn expand_template(
let safe_branch = branch.replace(['/', '\\'], "-");
let mut result = template
- .replace("{repo}", repo)
+ .replace("{main-worktree}", main_worktree)
.replace("{branch}", &safe_branch);
// Apply any extra variables
@@ -314,7 +312,7 @@ mod tests {
#[test]
fn test_default_config() {
let config = WorktrunkConfig::default();
- assert_eq!(config.worktree_path, "../{repo}.{branch}");
+ assert_eq!(config.worktree_path, "../{main-worktree}.{branch}");
}
#[test]
@@ -322,20 +320,20 @@ mod tests {
let config = WorktrunkConfig::default();
let toml = toml::to_string(&config).unwrap();
assert!(toml.contains("worktree-path"));
- assert!(toml.contains("../{repo}.{branch}"));
+ assert!(toml.contains("../{main-worktree}.{branch}"));
}
#[test]
fn test_load_config_defaults() {
// Without a config file or env vars, should return defaults
let config = WorktrunkConfig::load().unwrap();
- assert_eq!(config.worktree_path, "../{repo}.{branch}");
+ assert_eq!(config.worktree_path, "../{main-worktree}.{branch}");
}
#[test]
fn test_format_worktree_path() {
let config = WorktrunkConfig {
- worktree_path: "{repo}.{branch}".to_string(),
+ worktree_path: "{main-worktree}.{branch}".to_string(),
llm: LlmConfig::default(),
approved_commands: Vec::new(),
};
@@ -348,7 +346,7 @@ mod tests {
#[test]
fn test_format_worktree_path_custom_template() {
let config = WorktrunkConfig {
- worktree_path: "{repo}-{branch}".to_string(),
+ worktree_path: "{main-worktree}-{branch}".to_string(),
llm: LlmConfig::default(),
approved_commands: Vec::new(),
};
@@ -361,18 +359,21 @@ mod tests {
#[test]
fn test_format_worktree_path_only_branch() {
let config = WorktrunkConfig {
- worktree_path: "{branch}".to_string(),
+ worktree_path: ".worktrees/{main-worktree}/{branch}".to_string(),
llm: LlmConfig::default(),
approved_commands: Vec::new(),
};
- assert_eq!(config.format_path("myproject", "feature-x"), "feature-x");
+ assert_eq!(
+ config.format_path("myproject", "feature-x"),
+ ".worktrees/myproject/feature-x"
+ );
}
#[test]
fn test_format_worktree_path_with_slashes() {
// Slashes should be replaced with dashes to prevent directory traversal
let config = WorktrunkConfig {
- worktree_path: "{repo}.{branch}".to_string(),
+ worktree_path: "{main-worktree}.{branch}".to_string(),
llm: LlmConfig::default(),
approved_commands: Vec::new(),
};
@@ -385,13 +386,13 @@ mod tests {
#[test]
fn test_format_worktree_path_with_multiple_slashes() {
let config = WorktrunkConfig {
- worktree_path: "{branch}".to_string(),
+ worktree_path: ".worktrees/{main-worktree}/{branch}".to_string(),
llm: LlmConfig::default(),
approved_commands: Vec::new(),
};
assert_eq!(
config.format_path("myproject", "feature/sub/task"),
- "feature-sub-task"
+ ".worktrees/myproject/feature-sub-task"
);
}
@@ -399,13 +400,13 @@ mod tests {
fn test_format_worktree_path_with_backslashes() {
// Windows-style path separators should also be sanitized
let config = WorktrunkConfig {
- worktree_path: "{branch}".to_string(),
+ worktree_path: ".worktrees/{main-worktree}/{branch}".to_string(),
llm: LlmConfig::default(),
approved_commands: Vec::new(),
};
assert_eq!(
config.format_path("myproject", "feature\\foo"),
- "feature-foo"
+ ".worktrees/myproject/feature-foo"
);
}
@@ -433,9 +434,10 @@ mod tests {
#[test]
fn test_validate_accepts_relative_path() {
+ assert!(validate_worktree_path(".worktrees/{main-worktree}/{branch}").is_ok());
+ assert!(validate_worktree_path("../{main-worktree}.{branch}").is_ok());
+ assert!(validate_worktree_path("../../shared/{main-worktree}/{branch}").is_ok());
assert!(validate_worktree_path(".worktrees/{branch}").is_ok());
- assert!(validate_worktree_path("../{repo}.{branch}").is_ok());
- assert!(validate_worktree_path("../../shared/{branch}").is_ok());
}
#[test]
@@ -608,7 +610,12 @@ mod tests {
fn test_expand_template_basic() {
use std::collections::HashMap;
- let result = expand_template("../{repo}.{branch}", "myrepo", "feature-x", &HashMap::new());
+ let result = expand_template(
+ "../{main-worktree}.{branch}",
+ "myrepo",
+ "feature-x",
+ &HashMap::new(),
+ );
assert_eq!(result, "../myrepo.feature-x");
}
@@ -616,11 +623,21 @@ mod tests {
fn test_expand_template_sanitizes_branch() {
use std::collections::HashMap;
- let result = expand_template("{repo}/{branch}", "myrepo", "feature/foo", &HashMap::new());
+ let result = expand_template(
+ "{main-worktree}/{branch}",
+ "myrepo",
+ "feature/foo",
+ &HashMap::new(),
+ );
assert_eq!(result, "myrepo/feature-foo");
- let result = expand_template("{branch}", "myrepo", "feat\\bar", &HashMap::new());
- assert_eq!(result, "feat-bar");
+ let result = expand_template(
+ ".worktrees/{main-worktree}/{branch}",
+ "myrepo",
+ "feat\\bar",
+ &HashMap::new(),
+ );
+ assert_eq!(result, ".worktrees/myrepo/feat-bar");
}
#[test]
diff --git a/tests/integration_tests/config_list.rs b/tests/integration_tests/config_list.rs
index 14cee863b..e75f9742e 100644
--- a/tests/integration_tests/config_list.rs
+++ b/tests/integration_tests/config_list.rs
@@ -16,7 +16,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 = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "test-project"
@@ -70,7 +70,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 = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
"#,
)
.unwrap();
@@ -106,7 +106,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 = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
"#,
)
.unwrap();
diff --git a/tests/integration_tests/e2e_shell_post_start.rs b/tests/integration_tests/e2e_shell_post_start.rs
index 0a5180f7f..c224fb245 100644
--- a/tests/integration_tests/e2e_shell_post_start.rs
+++ b/tests/integration_tests/e2e_shell_post_start.rs
@@ -156,7 +156,7 @@ fn test_e2e_post_start_background_command(#[case] shell: &str) {
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
@@ -282,7 +282,7 @@ task2 = "sleep 0.5 && echo 'Task 2' > task2.txt"
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
@@ -368,7 +368,7 @@ fn test_bash_post_create_blocks() {
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
@@ -454,7 +454,7 @@ fish_bg = "sleep 0.5 && echo 'Fish background done' > fish_bg.txt"
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
diff --git a/tests/integration_tests/post_start_commands.rs b/tests/integration_tests/post_start_commands.rs
index 8cce93c2f..c611e993d 100644
--- a/tests/integration_tests/post_start_commands.rs
+++ b/tests/integration_tests/post_start_commands.rs
@@ -71,7 +71,7 @@ fn test_post_create_single_command() {
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
@@ -111,7 +111,7 @@ fn test_post_create_multiple_commands_array() {
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
@@ -158,7 +158,7 @@ setup = "echo 'Running setup'"
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
@@ -202,7 +202,7 @@ fn test_post_create_failing_command() {
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
@@ -232,7 +232,7 @@ fn test_post_create_template_expansion() {
fs::write(
config_dir.join("wt.toml"),
r#"post-create-command = [
- "echo 'Repo: {repo}' > info.txt",
+ "echo 'Repo: {main-worktree}' > info.txt",
"echo 'Branch: {branch}' >> info.txt",
"echo 'Worktree: {worktree}' >> info.txt",
"echo 'Root: {repo_root}' >> info.txt"
@@ -248,11 +248,11 @@ fn test_post_create_template_expansion() {
let repo_name = "main";
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
-command = "echo 'Repo: {repo}' > info.txt"
+command = "echo 'Repo: {main-worktree}' > info.txt"
[[approved-commands]]
project = "main"
@@ -331,7 +331,7 @@ fn test_post_start_single_background_command() {
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
@@ -390,7 +390,7 @@ task2 = "echo 'Task 2 running' > task2.txt"
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
@@ -446,7 +446,7 @@ server = "sleep 0.5 && echo 'Server running' > server.txt"
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
@@ -530,7 +530,7 @@ fn test_post_start_log_file_captures_output() {
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
@@ -607,7 +607,7 @@ fn test_post_start_invalid_command_handling() {
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
@@ -658,7 +658,7 @@ task3 = "echo 'TASK3_OUTPUT'"
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
@@ -760,7 +760,7 @@ fn test_execute_flag_with_post_start_commands() {
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
@@ -822,7 +822,7 @@ fn test_post_start_complex_shell_commands() {
fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
user_config_dir.join("config.toml"),
- r#"worktree-path = "../{repo}.{branch}"
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "main"
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index ba963a238..01c481490 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -279,7 +279,7 @@ fn test_switch_no_config_commands_skips_post_start_commands() {
fs::write(
user_config_dir.join("config.toml"),
format!(
- r#"worktree-path = "../{{repo}}.{{branch}}"
+ r#"worktree-path = "../{{main-worktree}}.{{branch}}"
[[approved-commands]]
project = "main"
diff --git a/tests/snapshots/integration__integration_tests__config_list__config_list_no_project.snap b/tests/snapshots/integration__integration_tests__config_list__config_list_no_project.snap
index 426c68636..30fd5cdbf 100644
--- a/tests/snapshots/integration__integration_tests__config_list__config_list_no_project.snap
+++ b/tests/snapshots/integration__integration_tests__config_list__config_list_no_project.snap
@@ -12,7 +12,7 @@ info:
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpRuEH5N
+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpq0vCwQ
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
@@ -21,7 +21,7 @@ success: true
exit_code: 0
----- stdout -----
Global Config: [TEMP_HOME]/.config/worktrunk/config.toml
- worktree-path = "../{repo}.{branch}"
+ worktree-path = "../{main-worktree}.{branch}"
Project Config: [REPO]/.config/wt.toml
💡 Not found
diff --git a/tests/snapshots/integration__integration_tests__config_list__config_list_outside_repo.snap b/tests/snapshots/integration__integration_tests__config_list__config_list_outside_repo.snap
index 24259ca26..aabadacc2 100644
--- a/tests/snapshots/integration__integration_tests__config_list__config_list_outside_repo.snap
+++ b/tests/snapshots/integration__integration_tests__config_list__config_list_outside_repo.snap
@@ -6,13 +6,13 @@ info:
- config
- list
env:
- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpqVUgYd
+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpxHds55
---
success: true
exit_code: 0
----- stdout -----
Global Config: [TEMP_HOME]/.config/worktrunk/config.toml
- worktree-path = "../{repo}.{branch}"
+ worktree-path = "../{main-worktree}.{branch}"
Project Config: Not in a git repository
diff --git a/tests/snapshots/integration__integration_tests__config_list__config_list_with_project.snap b/tests/snapshots/integration__integration_tests__config_list__config_list_with_project.snap
index 6b9c28621..0243ff9e9 100644
--- a/tests/snapshots/integration__integration_tests__config_list__config_list_with_project.snap
+++ b/tests/snapshots/integration__integration_tests__config_list__config_list_with_project.snap
@@ -12,7 +12,7 @@ info:
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpfh2xeS
+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpuCBKlR
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
@@ -21,7 +21,7 @@ success: true
exit_code: 0
----- stdout -----
Global Config: [TEMP_HOME]/.config/worktrunk/config.toml
- worktree-path = "../{repo}.{branch}"
+ worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "test-project"