Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Fix git worktree unlock hint to use path instead of branch (#412)
Maximilian Roosbadbfbbb4895
diff --git a/src/commands/repository_ext.rs b/src/commands/repository_ext.rsindex 09ef9b915..e4894f43e 100644--- a/src/commands/repository_ext.rs+++ b/src/commands/repository_ext.rs@@ -93,6 +93,7 @@ impl RepositoryCliExt for Repository {if wt.locked.is_some() {return Err(GitError::WorktreeLocked {branch: branch.into(),+ path: wt.path.clone(),reason: wt.locked.clone(),}.into());@@ -139,6 +140,7 @@ impl RepositoryCliExt for Repository {.unwrap_or_else(|| wt.dir_name().to_string());return Err(GitError::WorktreeLocked {branch: name,+ path: wt.path.clone(),reason: wt.locked.clone(),}.into());diff --git a/src/git/error.rs b/src/git/error.rsindex f7fc4b7a0..bf5b82a0b 100644--- a/src/git/error.rs+++ b/src/git/error.rs@@ -91,6 +91,7 @@ pub enum GitError {CannotRemoveMainWorktree,WorktreeLocked {branch: String,+ path: PathBuf,reason: Option<String>,},@@ -323,11 +324,16 @@ impl std::fmt::Display for GitError {)}- GitError::WorktreeLocked { branch, reason } => {+ GitError::WorktreeLocked {+ branch,+ path,+ reason,+ } => {let reason_text = match reason {Some(r) if !r.is_empty() => format!(" ({r})"),_ => String::new(),};+ let path_display = format_path_for_display(path);write!(f,"{}\n{}",@@ -335,7 +341,7 @@ impl std::fmt::Display for GitError {"Cannot remove <bold>{branch}</>, worktree is locked{reason_text}")),hint_message(cformat!(- "To unlock, run <bright-black>git worktree unlock {branch}</>"+ "To unlock, run <bright-black>git worktree unlock {path_display}</>")))}@@ -998,6 +1004,7 @@ mod tests {fn test_git_error_worktree_locked_with_reason() {let err = GitError::WorktreeLocked {branch: "feature".into(),+ path: PathBuf::from("/tmp/repo.feature"),reason: Some("Testing lock".into()),};let display = err.to_string();@@ -1005,7 +1012,7 @@ mod tests {assert!(display.contains("feature"));assert!(display.contains(", worktree is locked"));assert!(display.contains("(Testing lock)"));- assert!(display.contains("git worktree unlock"));+ assert!(display.contains("git worktree unlock /tmp/repo.feature"));}#[test]@@ -1013,6 +1020,7 @@ mod tests {// When git outputs "locked" without a reason, we get Some("")let err = GitError::WorktreeLocked {branch: "feature".into(),+ path: PathBuf::from("/tmp/repo.feature"),reason: Some("".into()),};let display = err.to_string();@@ -1023,7 +1031,7 @@ mod tests {!display.contains("locked ("),"should not show parentheses without reason");- assert!(display.contains("git worktree unlock"));+ assert!(display.contains("git worktree unlock /tmp/repo.feature"));}#[test]diff --git a/tests/snapshots/integration__integration_tests__remove__remove_locked_current_worktree.snap b/tests/snapshots/integration__integration_tests__remove__remove_locked_current_worktree.snapindex b638b3419..d89f88df6 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_locked_current_worktree.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_locked_current_worktree.snap@@ -31,4 +31,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mCannot remove [1mlocked-current[22m, worktree is locked (Do not remove)[39m-[2m↳[22m [2mTo unlock, run [90mgit worktree unlock locked-current[39m[22m+[2m↳[22m [2mTo unlock, run [90mgit worktree unlock _REPO_.locked-current[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_locked_detached_multi.snap b/tests/snapshots/integration__integration_tests__remove__remove_locked_detached_multi.snapindex d347b1325..b90e95094 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_locked_detached_multi.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_locked_detached_multi.snap@@ -34,4 +34,4 @@ exit_code: 1----- stderr -----[36m◎ Removing [1mother[22m worktree & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m[31m✗[39m [31mCannot remove [1mrepo.locked-detached[22m, worktree is locked (Locked detached)[39m-[2m↳[22m [2mTo unlock, run [90mgit worktree unlock repo.locked-detached[39m[22m+[2m↳[22m [2mTo unlock, run [90mgit worktree unlock _REPO_.locked-detached[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_locked_detached_worktree.snap b/tests/snapshots/integration__integration_tests__remove__remove_locked_detached_worktree.snapindex 98a16af0d..0641b94b5 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_locked_detached_worktree.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_locked_detached_worktree.snap@@ -31,4 +31,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mCannot remove [1mrepo.locked-detached[22m, worktree is locked (Detached and locked)[39m-[2m↳[22m [2mTo unlock, run [90mgit worktree unlock repo.locked-detached[39m[22m+[2m↳[22m [2mTo unlock, run [90mgit worktree unlock _REPO_.locked-detached[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_locked_worktree.snap b/tests/snapshots/integration__integration_tests__remove__remove_locked_worktree.snapindex fc5a83dc4..8815ae51c 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_locked_worktree.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_locked_worktree.snap@@ -32,4 +32,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mCannot remove [1mlocked-feature[22m, worktree is locked (Testing lock)[39m-[2m↳[22m [2mTo unlock, run [90mgit worktree unlock locked-feature[39m[22m+[2m↳[22m [2mTo unlock, run [90mgit worktree unlock _REPO_.locked-feature[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_locked_worktree_no_reason.snap b/tests/snapshots/integration__integration_tests__remove__remove_locked_worktree_no_reason.snapindex 48ecae678..700b6c3ce 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_locked_worktree_no_reason.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_locked_worktree_no_reason.snap@@ -32,4 +32,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mCannot remove [1mlocked-no-reason[22m, worktree is locked[39m-[2m↳[22m [2mTo unlock, run [90mgit worktree unlock locked-no-reason[39m[22m+[2m↳[22m [2mTo unlock, run [90mgit worktree unlock _REPO_.locked-no-reason[39m[22m