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.mdindex caa268f60..06bcfee38 100644--- a/README.md+++ b/README.md@@ -4,7 +4,7 @@[](https://worktrunk.dev)[](https://crates.io/crates/worktrunk)-[](https://opensource.org/licenses/MIT)+[](https://opensource.org/licenses/MIT)[](https://github.com/max-sixty/worktrunk/actions?query=branch%3Amain+workflow%3Aci)[](https://codecov.io/gh/max-sixty/worktrunk)[](https://github.com/max-sixty/worktrunk/stargazers)diff --git a/src/commands/process.rs b/src/commands/process.rsindex 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 fsmonitorlet 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 characterslet 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.rsindex 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 {