Skip to content

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

Improve path-occupied error message structure (#206)

Maximilian Roos9b2de2ccf76e
diff --git a/src/git/error.rs b/src/git/error.rs
index 7214014b6..e5ce5df0c 100644
--- a/src/git/error.rs
+++ b/src/git/error.rs
@@ -225,10 +225,12 @@ impl std::fmt::Display for GitError {
occupant,
} => {
let path_display = format_path_for_display(path);
- let error_suffix = if let Some(occupant_branch) = occupant {
- cformat!("existing worktree, on <bold>{occupant_branch}</>")
+ let error_detail = if let Some(occupant_branch) = occupant {
+ cformat!(
+ "existing worktree at <bold>{path_display}</> on <bold>{occupant_branch}</>"
+ )
} else {
- "existing worktree, detached".to_string()
+ cformat!("existing worktree at <bold>{path_display}</>, detached")
};
// Hint is self-contained (includes both path and branch)
let hint = hint_message(cformat!(
@@ -239,7 +241,7 @@ impl std::fmt::Display for GitError {
f,
"{}\n\n{}\n{}",
error_message(cformat!(
- "Cannot create worktree for <bold>{branch}</> at <bold>{path_display}</>: {error_suffix}"
+ "Cannot create worktree for <bold>{branch}</>: {error_detail}"
)),
hint,
format_with_gutter(&command, "", None)
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__worktree_path_occupied.snap b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__worktree_path_occupied.snap
index 0044acdcc..ca417e21b 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__worktree_path_occupied.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__worktree_path_occupied.snap
@@ -2,7 +2,7 @@
source: tests/integration_tests/git_error_display.rs
expression: err.to_string()
---
-❌ Cannot create worktree for feature-z at /tmp/repo.feature-z: existing worktree, on other-branch
+❌ Cannot create worktree for feature-z: existing worktree at /tmp/repo.feature-z on other-branch
πŸ’‘ Switch the worktree at /tmp/repo.feature-z to feature-z
  cd /tmp/repo.feature-z && git switch feature-z
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_error_main_worktree_on_different_branch.snap b/tests/snapshots/integration__integration_tests__switch__switch_error_main_worktree_on_different_branch.snap
index cd53ed6ee..8246e5a31 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_error_main_worktree_on_different_branch.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_error_main_worktree_on_different_branch.snap
@@ -29,7 +29,7 @@ exit_code: 1
----- stdout -----
----- stderr -----
-❌ Cannot create worktree for main at [REPO]: existing worktree, on feature
+❌ Cannot create worktree for main: existing worktree at [REPO] on feature
πŸ’‘ Switch the worktree at [REPO] to main
  cd [REPO] && git switch main
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied_detached.snap b/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied_detached.snap
index 8987de94a..0349da267 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied_detached.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied_detached.snap
@@ -29,7 +29,7 @@ exit_code: 1
----- stdout -----
----- stderr -----
-❌ Cannot create worktree for feature at [REPO].feature: existing worktree, detached
+❌ Cannot create worktree for feature: existing worktree at [REPO].feature, detached
πŸ’‘ Switch the worktree at [REPO].feature to feature
  cd [REPO].feature && git switch feature
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied_different_branch.snap b/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied_different_branch.snap
index 1eb61af83..b297f3030 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied_different_branch.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_error_path_occupied_different_branch.snap
@@ -29,7 +29,7 @@ exit_code: 1
----- stdout -----
----- stderr -----
-❌ Cannot create worktree for feature at [REPO].feature: existing worktree, on bugfix
+❌ Cannot create worktree for feature: existing worktree at [REPO].feature on bugfix
πŸ’‘ Switch the worktree at [REPO].feature to feature
  cd [REPO].feature && git switch feature