Skip to content

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

Show actual path in branch-worktree mismatch warning (#1377)

Maximilian Rooscc038ed07e70
diff --git a/.claude/skills/writing-user-outputs/SKILL.md b/.claude/skills/writing-user-outputs/SKILL.md
index 352b2bfd6..15070563c 100644
--- a/.claude/skills/writing-user-outputs/SKILL.md
+++ b/.claude/skills/writing-user-outputs/SKILL.md
@@ -321,7 +321,7 @@ When a command evaluates state, discovers something unexpected, and proceeds
anyway, the warning should come first:
```
-▲ Branch-worktree mismatch; expected feature @ ~/workspace/project.feature ⚑
+▲ Branch-worktree mismatch: feature @ ~/workspace/project.alias, expected @ ~/workspace/project.feature ⚑
◎ Removing feature worktree & branch in background (same commit as main, _)
```
@@ -329,7 +329,7 @@ Not:
```
◎ Removing feature worktree & branch in background (same commit as main, _)
-▲ Branch-worktree mismatch; expected feature @ ~/workspace/project.feature ⚑
+▲ Branch-worktree mismatch: feature @ ~/workspace/project.alias, expected @ ~/workspace/project.feature ⚑
```
Warnings that result from the action itself (something failed during execution)
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index 0f1b5283d..8200fd67c 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -168,10 +168,16 @@ fn format_switch_message(
/// Format a branch-worktree mismatch warning message.
///
/// Shows when a worktree is at a path that doesn't match the config template.
-fn format_path_mismatch_warning(branch: &str, expected_path: &Path) -> FormattedMessage {
+/// Displays both the actual location and the expected location.
+fn format_path_mismatch_warning(
+ branch: &str,
+ actual_path: &Path,
+ expected_path: &Path,
+) -> FormattedMessage {
+ let actual_display = format_path_for_display(actual_path);
let expected_display = format_path_for_display(expected_path);
warning_message(cformat!(
- "Branch-worktree mismatch; expected <bold>{branch}</> @ <bold>{expected_display}</> <red>⚑</>"
+ "Branch-worktree mismatch: <bold>{branch}</> @ <bold>{actual_display}</>, expected @ <bold>{expected_display}</> <red>⚑</>"
))
}
@@ -479,7 +485,7 @@ pub fn handle_switch_output(
let branch_worktree_mismatch_warning = branch_info
.expected_path
.as_ref()
- .map(|expected| format_path_mismatch_warning(&branch_info.branch, expected));
+ .map(|expected| format_path_mismatch_warning(&branch_info.branch, &path, expected));
let display_path_for_hooks = match result {
SwitchResult::AlreadyAt(_) => {
@@ -1162,7 +1168,10 @@ fn handle_removed_worktree_output(ctx: RemovedWorktreeOutputContext<'_>) -> anyh
if background {
// Background mode: show warning before decision announcement
if let Some(expected) = expected_path {
- eprintln!("{}", format_path_mismatch_warning(branch_name, expected));
+ eprintln!(
+ "{}",
+ format_path_mismatch_warning(branch_name, worktree_path, expected)
+ );
}
// Background mode: spawn detached process
@@ -1221,7 +1230,10 @@ fn handle_removed_worktree_output(ctx: RemovedWorktreeOutputContext<'_>) -> anyh
// Foreground mode: show warning after progress (contextual info during operation)
if let Some(expected) = expected_path {
- eprintln!("{}", format_path_mismatch_warning(branch_name, expected));
+ eprintln!(
+ "{}",
+ format_path_mismatch_warning(branch_name, worktree_path, expected)
+ );
}
// Stop fsmonitor daemon first (best effort - ignore errors)
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_path_mismatch_warning.snap b/tests/snapshots/integration__integration_tests__remove__remove_path_mismatch_warning.snap
index c414b7e18..ec59fc180 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_path_mismatch_warning.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_path_mismatch_warning.snap
@@ -19,16 +19,20 @@ info:
LANG: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
SHELL: ""
TERM: alacritty
USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -38,5 +42,5 @@ exit_code: 0
----- stdout -----
----- stderr -----
-▲ Branch-worktree mismatch; expected feature @ _REPO_.feature ⚑
+▲ Branch-worktree mismatch: feature @ _PARENT_/weird-path-for-feature, expected @ _REPO_.feature ⚑
◎ Removing feature worktree & branch in background (same commit as main, _)
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_path_mismatch_warning_foreground.snap b/tests/snapshots/integration__integration_tests__remove__remove_path_mismatch_warning_foreground.snap
index 37e56d6a7..24b6788a1 100644
--- a/tests/snapshots/integration__integration_tests__remove__remove_path_mismatch_warning_foreground.snap
+++ b/tests/snapshots/integration__integration_tests__remove__remove_path_mismatch_warning_foreground.snap
@@ -20,16 +20,20 @@ info:
LANG: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
SHELL: ""
TERM: alacritty
USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -40,5 +44,5 @@ exit_code: 0
----- stderr -----
◎ Removing feature-fg worktree...
-▲ Branch-worktree mismatch; expected feature-fg @ _REPO_.feature-fg ⚑
+▲ Branch-worktree mismatch: feature-fg @ _PARENT_/another-weird-path, expected @ _REPO_.feature-fg ⚑
✓ Removed feature-fg worktree & branch (same commit as main, _)
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_already_at_branch_worktree_mismatch.snap b/tests/snapshots/integration__integration_tests__switch__switch_already_at_branch_worktree_mismatch.snap
index a6766fb3b..dfd80e110 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_already_at_branch_worktree_mismatch.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_already_at_branch_worktree_mismatch.snap
@@ -42,6 +42,6 @@ exit_code: 0
----- stdout -----
----- stderr -----
-▲ Branch-worktree mismatch; expected feature-already @ _REPO_.feature-already ⚑
+▲ Branch-worktree mismatch: feature-already @ _PARENT_/wrong-path-already, expected @ _REPO_.feature-already ⚑
○ Already on worktree for feature-already @ _PARENT_/wrong-path-already
↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_branch_worktree_mismatch_no_shell.snap b/tests/snapshots/integration__integration_tests__switch__switch_branch_worktree_mismatch_no_shell.snap
index 65d49210b..eaab2a9ab 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_branch_worktree_mismatch_no_shell.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_branch_worktree_mismatch_no_shell.snap
@@ -42,6 +42,6 @@ exit_code: 0
----- stdout -----
----- stderr -----
-▲ Branch-worktree mismatch; expected feature-mismatch @ _REPO_.feature-mismatch ⚑
+▲ Branch-worktree mismatch: feature-mismatch @ _PARENT_/wrong-path-no-shell, expected @ _REPO_.feature-mismatch ⚑
▲ Worktree for feature-mismatch @ _PARENT_/wrong-path-no-shell, but cannot change directory — shell integration not installed
↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_branch_worktree_mismatch_shows_hint.snap b/tests/snapshots/integration__integration_tests__switch__switch_branch_worktree_mismatch_shows_hint.snap
index 218265713..c6d4116d3 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_branch_worktree_mismatch_shows_hint.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_branch_worktree_mismatch_shows_hint.snap
@@ -19,17 +19,21 @@ info:
LANG: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
SHELL: ""
TERM: alacritty
USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
WORKTRUNK_DIRECTIVE_FILE: "[DIRECTIVE_FILE]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
@@ -39,5 +43,5 @@ exit_code: 0
----- stdout -----
----- stderr -----
-▲ Branch-worktree mismatch; expected feature @ _REPO_.feature ⚑
+▲ Branch-worktree mismatch: feature @ _PARENT_/wrong-path, expected @ _REPO_.feature ⚑
○ Switched to worktree for feature @ _PARENT_/wrong-path