Skip to content

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.rs
index 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.rs
index 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.snap
index 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 -----
✗ Cannot remove locked-current, worktree is locked (Do not remove)
-↳ To unlock, run git worktree unlock locked-current
+↳ To unlock, run git worktree unlock _REPO_.locked-current
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_locked_detached_multi.snap b/tests/snapshots/integration__integration_tests__remove__remove_locked_detached_multi.snap
index 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 -----
◎ Removing other worktree & branch in background (same commit as main, _)
✗ Cannot remove repo.locked-detached, worktree is locked (Locked detached)
-↳ To unlock, run git worktree unlock repo.locked-detached
+↳ To unlock, run git worktree unlock _REPO_.locked-detached
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_locked_detached_worktree.snap b/tests/snapshots/integration__integration_tests__remove__remove_locked_detached_worktree.snap
index 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 -----
✗ Cannot remove repo.locked-detached, worktree is locked (Detached and locked)
-↳ To unlock, run git worktree unlock repo.locked-detached
+↳ To unlock, run git worktree unlock _REPO_.locked-detached
diff --git a/tests/snapshots/integration__integration_tests__remove__remove_locked_worktree.snap b/tests/snapshots/integration__integration_tests__remove__remove_locked_worktree.snap
index 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 -----
✗ Cannot remove locked-feature, worktree is locked (Testing lock)
-↳ To unlock, run git worktree unlock locked-feature
+↳ To unlock, run git worktree unlock _REPO_.locked-feature
diff --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.snap
index 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 -----
✗ Cannot remove locked-no-reason, worktree is locked
-↳ To unlock, run git worktree unlock locked-no-reason
+↳ To unlock, run git worktree unlock _REPO_.locked-no-reason