Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: Stop fsmonitor daemon during worktree removal
Maximilian Roos741377976533
diff --git a/src/cli.rs b/src/cli.rsindex 31688f90e..8dbab994e 100644--- a/src/cli.rs+++ b/src/cli.rs@@ -640,6 +640,8 @@ Removes worktree directory, git metadata, and branch. Requires clean working tre- Logs: `.git/wt-logs/{branch}-remove.log`- Use `--no-background` for foreground (blocking)+**Cleanup**: Stops any git fsmonitor daemon for the worktree before removal. This prevents orphaned processes when using builtin fsmonitor (`core.fsmonitor=true`). No effect on Watchman users.+## EXAMPLESRemove current worktree and branch:diff --git a/src/output/handlers.rs b/src/output/handlers.rsindex 23fbe29e4..e78f44d7e 100644--- a/src/output/handlers.rs+++ b/src/output/handlers.rs@@ -164,15 +164,25 @@ fn build_remove_command(let worktree_escaped = escape(worktree_path_str.as_ref().into());let branch_escaped = escape(branch_name.into());+ // 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",+ worktree_escaped+ );+if should_delete_branch {- // Remove worktree and delete branch+ // Stop fsmonitor, remove worktree, and delete branchformat!(- "git worktree remove {} && git branch -D {}",- worktree_escaped, branch_escaped+ "{} && git worktree remove {} && git branch -D {}",+ stop_fsmonitor, worktree_escaped, branch_escaped)} else {- // Just remove the worktree- format!("git worktree remove {}", worktree_escaped)+ // Stop fsmonitor and remove the worktree+ format!(+ "{} && git worktree remove {}",+ stop_fsmonitor, worktree_escaped+ )}}@@ -251,6 +261,12 @@ pub fn handle_remove_output(Ok(())} else {// Synchronous mode: remove immediately and report actual results++ // Stop fsmonitor daemon first (best effort - ignore errors)+ // This prevents zombie daemons from accumulating when using builtin fsmonitor+ let target_repo = worktrunk::git::Repository::at(worktree_path);+ let _ = target_repo.run_command(&["fsmonitor--daemon", "stop"]);+// Track whether branch was actually deleted (will be computed based on deletion attempt)if let Err(err) = repo.remove_worktree(worktree_path) {anyhow::bail!(diff --git a/tests/snapshots/integration__integration_tests__help__help_remove.snap b/tests/snapshots/integration__integration_tests__help__help_remove.snapindex 0ba10eac6..6314d4c39 100644--- a/tests/snapshots/integration__integration_tests__help__help_remove.snap+++ b/tests/snapshots/integration__integration_tests__help__help_remove.snap@@ -61,6 +61,10 @@ Background removal (default):- Logs: .git/wt-logs/{branch}-remove.log- Use --no-background for foreground (blocking)+Cleanup: Stops any git fsmonitor daemon for the worktree before removal. This+prevents orphaned processes when using builtin fsmonitor (core.fsmonitor=true).+No effect on Watchman users.+[38;5;10mEXAMPLES[39mRemove current worktree and branch: