Skip to content

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

fix: shell precedence, missing escaping, and license badge drift (#1584)

worktrunk-bot3e1667304162
diff --git a/README.md b/README.md
index caa268f60..06bcfee38 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
[![Docs](https://img.shields.io/badge/docs-worktrunk.dev-blue?style=for-the-badge&logo=gitbook)](https://worktrunk.dev)
[![Crates.io](https://img.shields.io/crates/v/worktrunk?style=for-the-badge&logo=rust)](https://crates.io/crates/worktrunk)
-[![License: MIT](https://img.shields.io/badge/license-MIT-blue?style=for-the-badge)](https://opensource.org/licenses/MIT)
+[![License: MIT OR Apache-2.0](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue?style=for-the-badge)](https://opensource.org/licenses/MIT)
[![CI](https://img.shields.io/github/actions/workflow/status/max-sixty/worktrunk/ci.yaml?event=push&branch=main&style=for-the-badge&logo=github)](https://github.com/max-sixty/worktrunk/actions?query=branch%3Amain+workflow%3Aci)
[![Codecov](https://img.shields.io/codecov/c/github/max-sixty/worktrunk?style=for-the-badge&logo=codecov)](https://codecov.io/gh/max-sixty/worktrunk)
[![Stars](https://img.shields.io/github/stars/max-sixty/worktrunk?style=for-the-badge&logo=github)](https://github.com/max-sixty/worktrunk/stargazers)
diff --git a/src/commands/process.rs b/src/commands/process.rs
index d22ca1533..d0162dd9f 100644
--- a/src/commands/process.rs
+++ b/src/commands/process.rs
@@ -454,7 +454,7 @@ pub fn build_remove_command(
// Stop fsmonitor daemon first (best effort - ignore errors)
// This prevents zombie daemons from accumulating when using builtin fsmonitor
let stop_fsmonitor = format!(
- "git -C {} fsmonitor--daemon stop 2>/dev/null || true",
+ "{{ git -C {} fsmonitor--daemon stop 2>/dev/null || true; }}",
worktree_escaped
);
@@ -568,20 +568,20 @@ mod tests {
let path = PathBuf::from("/tmp/test-worktree");
// Without branch deletion, without force
- assert_snapshot!(build_remove_command(&path, None, false), @"sleep 1 && git -C /tmp/test-worktree fsmonitor--daemon stop 2>/dev/null || true && git worktree remove /tmp/test-worktree");
+ assert_snapshot!(build_remove_command(&path, None, false), @"sleep 1 && { git -C /tmp/test-worktree fsmonitor--daemon stop 2>/dev/null || true; } && git worktree remove /tmp/test-worktree");
// With branch deletion, without force
- assert_snapshot!(build_remove_command(&path, Some("feature-branch"), false), @"sleep 1 && git -C /tmp/test-worktree fsmonitor--daemon stop 2>/dev/null || true && git worktree remove /tmp/test-worktree && git branch -D feature-branch");
+ assert_snapshot!(build_remove_command(&path, Some("feature-branch"), false), @"sleep 1 && { git -C /tmp/test-worktree fsmonitor--daemon stop 2>/dev/null || true; } && git worktree remove /tmp/test-worktree && git branch -D feature-branch");
// With force flag
- assert_snapshot!(build_remove_command(&path, None, true), @"sleep 1 && git -C /tmp/test-worktree fsmonitor--daemon stop 2>/dev/null || true && git worktree remove --force /tmp/test-worktree");
+ assert_snapshot!(build_remove_command(&path, None, true), @"sleep 1 && { git -C /tmp/test-worktree fsmonitor--daemon stop 2>/dev/null || true; } && git worktree remove --force /tmp/test-worktree");
// With branch deletion and force
- assert_snapshot!(build_remove_command(&path, Some("feature-branch"), true), @"sleep 1 && git -C /tmp/test-worktree fsmonitor--daemon stop 2>/dev/null || true && git worktree remove --force /tmp/test-worktree && git branch -D feature-branch");
+ assert_snapshot!(build_remove_command(&path, Some("feature-branch"), true), @"sleep 1 && { git -C /tmp/test-worktree fsmonitor--daemon stop 2>/dev/null || true; } && git worktree remove --force /tmp/test-worktree && git branch -D feature-branch");
// Shell escaping for special characters
let special_path = PathBuf::from("/tmp/test worktree");
- assert_snapshot!(build_remove_command(&special_path, Some("feature/branch"), false), @"sleep 1 && git -C '/tmp/test worktree' fsmonitor--daemon stop 2>/dev/null || true && git worktree remove '/tmp/test worktree' && git branch -D feature/branch");
+ assert_snapshot!(build_remove_command(&special_path, Some("feature/branch"), false), @"sleep 1 && { git -C '/tmp/test worktree' fsmonitor--daemon stop 2>/dev/null || true; } && git worktree remove '/tmp/test worktree' && git branch -D feature/branch");
}
#[test]
diff --git a/src/git/error.rs b/src/git/error.rs
index 5e9706eea..578d8f434 100644
--- a/src/git/error.rs
+++ b/src/git/error.rs
@@ -484,7 +484,9 @@ impl GitError {
"there's a detached worktree at the expected path <bold>{path_display}</>"
)
};
- let command = format!("cd {path_display} && git switch {branch}");
+ let escaped_path = escape(path.to_string_lossy());
+ let escaped_branch = escape(Cow::Borrowed(branch.as_str()));
+ let command = format!("cd {escaped_path} && git switch {escaped_branch}");
write!(
f,
"{}\n{}",
@@ -1300,6 +1302,22 @@ mod tests {
");
}
+ #[test]
+ fn snapshot_worktree_path_occupied_special_chars() {
+ // Spaces in path and branch name require shell escaping in the hint command
+ let err = GitError::WorktreePathOccupied {
+ branch: "feature/my branch".into(),
+ path: PathBuf::from("/tmp/my repo"),
+ occupant: Some("main".into()),
+ };
+ let output = err.to_string();
+ // The hint command must quote the path and branch for safe shell execution
+ assert!(
+ output.contains("cd '/tmp/my repo' && git switch 'feature/my branch'"),
+ "expected shell-escaped command in hint, got: {output}"
+ );
+ }
+
#[test]
fn snapshot_worktree_creation_failed() {
let err = GitError::WorktreeCreationFailed {