Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(remove): show progress message after pre-remove hooks (#510)
Maximilian Roosa2c7878fa124
diff --git a/src/commands/worktree.rs b/src/commands/worktree.rsindex 10970b269..516b787e7 100644--- a/src/commands/worktree.rs+++ b/src/commands/worktree.rs@@ -754,18 +754,11 @@ pub fn handle_remove(no_delete_branch: bool,force_delete: bool,force_worktree: bool,- background: bool,config: &WorktrunkConfig,) -> anyhow::Result<RemoveResult> {let repo = Repository::current();- // Show progress (unless running in background - output handler will show command)- if !background {- crate::output::print(progress_message(cformat!(- "Removing <bold>{worktree_name}</> worktree..."- )))?;- }-+ // Progress message is shown in handle_removed_worktree_output() after pre-remove hooks runrepo.prepare_worktree_removal(RemoveTarget::Branch(worktree_name),BranchDeletionMode::from_flags(no_delete_branch, force_delete),@@ -782,16 +775,11 @@ pub fn handle_remove_current(no_delete_branch: bool,force_delete: bool,force_worktree: bool,- background: bool,config: &WorktrunkConfig,) -> anyhow::Result<RemoveResult> {let repo = Repository::current();- // Show progress (unless running in background - output handler will show command)- if !background {- crate::output::print(progress_message("Removing current worktree..."))?;- }-+ // Progress message is shown in handle_removed_worktree_output() after pre-remove hooks runrepo.prepare_worktree_removal(RemoveTarget::Current,BranchDeletionMode::from_flags(no_delete_branch, force_delete),diff --git a/src/main.rs b/src/main.rsindex 64c566994..497a59403 100644--- a/src/main.rs+++ b/src/main.rs@@ -1484,14 +1484,9 @@ fn main() {if branches.is_empty() {// No branches specified, remove current worktree// Uses path-based removal to handle detached HEAD state- let result = handle_remove_current(- !delete_branch,- force_delete,- force,- background,- &config,- )- .context("Failed to remove worktree")?;+ let result =+ handle_remove_current(!delete_branch, force_delete, force, &config)+ .context("Failed to remove worktree")?;// Approval was handled at the gate// Post-switch hooks are spawned internally by handle_remove_outputhandle_remove_output(&result, background, verify)@@ -1545,7 +1540,6 @@ fn main() {!delete_branch,force_delete,force,- background,&config,) {Ok(result) => {@@ -1560,14 +1554,7 @@ fn main() {// Handle branch-only cases (no worktree)for branch in &branch_only {- match handle_remove(- branch,- !delete_branch,- force_delete,- force,- background,- &config,- ) {+ match handle_remove(branch, !delete_branch, force_delete, force, &config) {Ok(result) => {handle_remove_output(&result, background, verify)?;}@@ -1581,13 +1568,7 @@ fn main() {// Remove current worktree last (if it was in the list)// Post-switch hooks are spawned internally by handle_remove_outputif let Some((_path, _branch)) = current {- match handle_remove_current(- !delete_branch,- force_delete,- force,- background,- &config,- ) {+ match handle_remove_current(!delete_branch, force_delete, force, &config) {Ok(result) => {handle_remove_output(&result, background, verify)?;}diff --git a/src/output/handlers.rs b/src/output/handlers.rsindex 12c3b30c5..b2147f3b5 100644--- a/src/output/handlers.rs+++ b/src/output/handlers.rs@@ -619,6 +619,10 @@ fn handle_removed_worktree_output(None,)?;} else {+ // Progress message after pre-remove hooks, before actual removal+ super::print(progress_message(+ "Removing worktree (detached HEAD, no branch to delete)...",+ ))?;let target_repo = worktrunk::git::Repository::at(worktree_path);let _ = target_repo.run_command(&["fsmonitor--daemon", "stop"]);if let Err(err) = repo.remove_worktree(worktree_path, force_worktree) {@@ -742,6 +746,11 @@ fn handle_removed_worktree_output(} else {// Synchronous mode: remove immediately and report actual results+ // Progress message after pre-remove hooks, before actual removal+ super::print(progress_message(cformat!(+ "Removing <bold>{branch_name}</> worktree..."+ )))?;+// Stop fsmonitor daemon first (best effort - ignore errors)// This prevents zombie daemons from accumulating when using builtin fsmonitorlet target_repo = worktrunk::git::Repository::at(worktree_path);diff --git a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_executes.snap b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_executes.snapindex 6ae597ebb..beaf7cf8b 100644--- a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_executes.snap+++ b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_executes.snap@@ -9,7 +9,7 @@ info:env:APPDATA: "[TEST_CONFIG_HOME]"CLICOLOR_FORCE: "1"- COLUMNS: "150"+ COLUMNS: "500"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"@@ -33,8 +33,8 @@ exit_code: 0----- stdout ---------- stderr ------[36m◎[39m [36mRemoving [1mfeature-hook[22m worktree...[39m[36m◎[39m [36mRunning pre-remove project hook @ [1m_REPO_.feature-hook[22m:[39m[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'About to remove worktree'[0m[2m[0mAbout to remove worktree+[36m◎[39m [36mRemoving [1mfeature-hook[22m worktree...[39m[32m✓ Removed [1mfeature-hook[22m worktree & branch (same commit as [1mmain[22m,[39m [2m_[22m[32m)[39mdiff --git a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_failure_aborts.snap b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_failure_aborts.snapindex cf398862d..e888e85e5 100644--- a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_failure_aborts.snap+++ b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_failure_aborts.snap@@ -9,7 +9,7 @@ info:env:APPDATA: "[TEST_CONFIG_HOME]"CLICOLOR_FORCE: "1"- COLUMNS: "150"+ COLUMNS: "500"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"@@ -33,7 +33,6 @@ exit_code: 1----- stdout ---------- stderr ------[36m◎[39m [36mRemoving [1mfeature-fail[22m worktree...[39m[36m◎[39m [36mRunning pre-remove project hook @ [1m_REPO_.feature-fail[22m:[39m[107m [0m [2m[0m[2m[34mexit[0m[2m 1[0m[31m✗[39m [31mpre-remove command failed: exit status: 1[39mdiff --git a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_runs_for_detached_head.snap b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_runs_for_detached_head.snapindex 6418b8985..aa6de5e1b 100644--- a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_runs_for_detached_head.snap+++ b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_runs_for_detached_head.snap@@ -8,7 +8,7 @@ info:env:APPDATA: "[TEST_CONFIG_HOME]"CLICOLOR_FORCE: "1"- COLUMNS: "150"+ COLUMNS: "500"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"@@ -32,7 +32,7 @@ exit_code: 0----- stdout ---------- stderr ------[36m◎[39m [36mRemoving current worktree...[39m[36m◎[39m [36mRunning pre-remove project hook:[39m[107m [0m [2m[0m[2m[34mtouch[0m[2m _REPO_/m.txt-[0m[32m✓[39m [32mRemoved worktree (detached HEAD, no branch to delete)[39m+[0m[36m◎[39m [36mRemoving worktree (detached HEAD, no branch to delete)...[39m+[32m✓[39m [32mRemoved worktree (detached HEAD, no branch to delete)[39mdiff --git a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_template_variables.snap b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_template_variables.snapindex c2a89c90a..f982587c0 100644--- a/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_template_variables.snap+++ b/tests/snapshots/integration__integration_tests__remove__pre_remove_hook_template_variables.snap@@ -9,7 +9,7 @@ info:env:APPDATA: "[TEST_CONFIG_HOME]"CLICOLOR_FORCE: "1"- COLUMNS: "150"+ COLUMNS: "500"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"@@ -33,7 +33,6 @@ exit_code: 0----- stdout ---------- stderr ------[36m◎[39m [36mRemoving [1mfeature-templates[22m worktree...[39m[36m◎[39m [36mRunning pre-remove [1mproject:branch[22m @ [1m_REPO_.feature-templates[22m:[39m[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Branch: feature-templates'[0m[2m[0mBranch: feature-templates@@ -43,4 +42,5 @@ exit_code: 0[36m◎[39m [36mRunning pre-remove [1mproject:worktree_name[22m @ [1m_REPO_.feature-templates[22m:[39m[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'Name: repo.feature-templates'[0m[2m[0mName: repo.feature-templates+[36m◎[39m [36mRemoving [1mfeature-templates[22m worktree...[39m[32m✓ Removed [1mfeature-templates[22m worktree & branch (same commit as [1mmain[22m,[39m [2m_[22m[32m)[39mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_foreground_detached_head.snap b/tests/snapshots/integration__integration_tests__remove__remove_foreground_detached_head.snapindex 8c1cb8754..a5c14dcc3 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_foreground_detached_head.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_foreground_detached_head.snap@@ -8,7 +8,7 @@ info:env:APPDATA: "[TEST_CONFIG_HOME]"CLICOLOR_FORCE: "1"- COLUMNS: "150"+ COLUMNS: "500"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"@@ -32,5 +32,5 @@ exit_code: 0----- stdout ---------- stderr ------[36m◎[39m [36mRemoving current worktree...[39m+[36m◎[39m [36mRemoving worktree (detached HEAD, no branch to delete)...[39m[32m✓[39m [32mRemoved worktree (detached HEAD, no branch to delete)[39mdiff --git a/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__from_linked_succeeds.snap b/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__from_linked_succeeds.snapindex eea3a9cbf..ffa9e82b2 100644--- a/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__from_linked_succeeds.snap+++ b/tests/snapshots/integration__integration_tests__remove__remove_main_vs_linked__from_linked_succeeds.snap@@ -8,7 +8,7 @@ info:env:APPDATA: "[TEST_CONFIG_HOME]"CLICOLOR_FORCE: "1"- COLUMNS: "150"+ COLUMNS: "500"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"@@ -32,7 +32,7 @@ exit_code: 0----- stdout ---------- stderr ------[36m◎[39m [36mRemoving current worktree...[39m+[36m◎[39m [36mRemoving [1mfeature[22m worktree...[39m[32m✓ Removed [1mfeature[22m worktree & branch (same commit as [1mmain[22m,[39m [2m_[22m[32m)[39m[33m▲[39m [33mCannot change directory — shell integration not installed[39m[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22m