Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Refactor: Canonicalize worktree paths for consistent display
Maximilian Roose21134587864
diff --git a/src/commands/worktree.rs b/src/commands/worktree.rsindex 60331b32a..2ee67fc9b 100644--- a/src/commands/worktree.rs+++ b/src/commands/worktree.rs@@ -134,7 +134,9 @@ pub fn handle_switch(// Check if worktree already exists for this branchmatch repo.worktree_for_branch(branch)? {Some(existing_path) if existing_path.exists() => {- return Ok(SwitchResult::ExistingWorktree(existing_path));+ // Canonicalize the path for cleaner display+ let canonical_existing_path = existing_path.canonicalize().unwrap_or(existing_path);+ return Ok(SwitchResult::ExistingWorktree(canonical_existing_path));}Some(_) => {return Err(GitError::CommandFailed(format_error_with_bold(@@ -173,8 +175,11 @@ pub fn handle_switch(repo.run_command(&args).map_err(|e| GitError::CommandFailed(format!("Failed to create worktree: {}", e)))?;+ // Canonicalize the path for cleaner display+ let canonical_path = worktree_path.canonicalize().unwrap_or(worktree_path);+Ok(SwitchResult::CreatedWorktree {- path: worktree_path,+ path: canonical_path,created_branch: create,})}@@ -209,8 +214,13 @@ pub fn handle_remove() -> Result<RemoveResult, GitError> {);}+ // Canonicalize the path for cleaner display+ let canonical_primary_path = primary_worktree_dir+ .canonicalize()+ .unwrap_or(primary_worktree_dir);+Ok(RemoveResult::RemovedWorktree {- primary_path: primary_worktree_dir,+ primary_path: canonical_primary_path,})} else {// In main repo but not on default branch: switch to defaultdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_create_new.snap b/tests/snapshots/integration__integration_tests__switch__switch_create_new.snapindex 0ef76e70f..729593c43 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_create_new.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_create_new.snap@@ -20,7 +20,7 @@ info:success: trueexit_code: 0----- stdout ------Created new branch and worktree for 'feature-x' at [REPO]/../main.feature-x+Created new branch and worktree for 'feature-x' at [REPO].feature-xNote: Use 'wt switch' (with shell integration) for automatic cd----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__switch__switch_internal_mode.snap b/tests/snapshots/integration__integration_tests__switch__switch_internal_mode.snapindex dbe808c93..d878b7a95 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_internal_mode.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_internal_mode.snap@@ -8,6 +8,7 @@ info:- "--internal"- internal-testenv:+ CLICOLOR_FORCE: "1"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: /dev/null@@ -20,7 +21,7 @@ info:success: trueexit_code: 0----- stdout ------__WORKTRUNK_CD__[REPO]/../main.internal-test-Created new branch and worktree for 'internal-test' at [REPO]/../main.internal-test+__WORKTRUNK_CD__[REPO].internal-test+Created new branch and worktree for 'internal-test' at [REPO].internal-test----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__switch__switch_with_base.snap b/tests/snapshots/integration__integration_tests__switch__switch_with_base.snapindex c9e52d6a8..5e5279728 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_with_base.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_with_base.snap@@ -22,7 +22,7 @@ info:success: trueexit_code: 0----- stdout ------Created new branch and worktree for 'feature-with-base' at [REPO]/../main.feature-with-base+Created new branch and worktree for 'feature-with-base' at [REPO].feature-with-baseNote: Use 'wt switch' (with shell integration) for automatic cd----- stderr -----