Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(output): prune summary & post-remove hook display path (#1344)
Maximilian Roos1e6a448dfa8b
diff --git a/src/commands/step_commands.rs b/src/commands/step_commands.rsindex 408cd0f7f..291c1d36b 100644--- a/src/commands/step_commands.rs+++ b/src/commands/step_commands.rs@@ -1334,11 +1334,14 @@ pub fn step_prune(dry_run: bool, yes: bool, min_age: &str, foreground: bool) ->BranchOnly,}- /// Build a human-readable count like "2 worktrees (with branches), 1 branch".+ /// Build a human-readable count like "3 worktrees & branches".+ ///+ /// Worktree + branch is the default pair (matching progress messages'+ /// "worktree & branch" pattern). Unpaired items listed separately.fn prune_summary(candidates: &[Candidate]) -> String {- let mut worktree_with_branch = 0;- let mut branch_only = 0;- let mut detached_worktree = 0;+ let mut worktree_with_branch = 0usize;+ let mut detached_worktree = 0usize;+ let mut branch_only = 0usize;for c in candidates {match (&c.kind, &c.branch) {(CandidateKind::BranchOnly, _) => branch_only += 1,@@ -1353,12 +1356,20 @@ pub fn step_prune(dry_run: bool, yes: bool, min_age: &str, foreground: bool) ->let mut parts = Vec::new();if worktree_with_branch > 0 {let noun = if worktree_with_branch == 1 {- "worktree (with branch)"+ "worktree & branch"} else {- "worktrees (with branches)"+ "worktrees & branches"};parts.push(format!("{worktree_with_branch} {noun}"));}+ if detached_worktree > 0 {+ let noun = if detached_worktree == 1 {+ "worktree"+ } else {+ "worktrees"+ };+ parts.push(format!("{detached_worktree} {noun}"));+ }if branch_only > 0 {let noun = if branch_only == 1 {"branch"@@ -1367,14 +1378,6 @@ pub fn step_prune(dry_run: bool, yes: bool, min_age: &str, foreground: bool) ->};parts.push(format!("{branch_only} {noun}"));}- if detached_worktree > 0 {- let noun = if detached_worktree == 1 {- "detached worktree"- } else {- "detached worktrees"- };- parts.push(format!("{detached_worktree} {noun}"));- }parts.join(", ")}diff --git a/src/output/handlers.rs b/src/output/handlers.rsindex f724e22c6..0f1b5283d 100644--- a/src/output/handlers.rs+++ b/src/output/handlers.rs@@ -782,7 +782,15 @@ fn spawn_hooks_after_remove(return Ok(());};let repo = Repository::at(main_path)?;- let display_path = super::post_hook_display_path(main_path);+ // When removing the current worktree, user cd's to main_path → use post_hook logic+ // (suppresses path if shell integration will cd there).+ // When removing a different worktree, user stays at cwd → use pre_hook logic+ // (shows path if main_path differs from cwd).+ let display_path = if changed_directory {+ super::post_hook_display_path(main_path)+ } else {+ super::pre_hook_display_path(main_path)+ };// All hooks use remove_ctx for spawning: log files are named after the removed// branch since both post-remove and post-switch are consequences of that removal.diff --git a/tests/integration_tests/step_prune.rs b/tests/integration_tests/step_prune.rsindex b4be0eeff..1f86b40b3 100644--- a/tests/integration_tests/step_prune.rs+++ b/tests/integration_tests/step_prune.rs@@ -198,6 +198,29 @@ fn test_prune_removes_integrated_detached(mut repo: TestRepo) {);}+/// Prune removes multiple integrated detached HEAD worktrees (exercises plural "worktrees")+#[rstest]+fn test_prune_removes_multiple_detached(mut repo: TestRepo) {+ repo.commit("initial");++ // Two worktrees at same commit as main, then detach both+ repo.add_worktree("detached-a");+ repo.detach_head_in_worktree("detached-a");+ repo.add_worktree("detached-b");+ repo.detach_head_in_worktree("detached-b");++ assert_cmd_snapshot!(make_snapshot_cmd(+ &repo,+ "step",+ &["prune", "--yes", "--min-age=0s"],+ None+ ));++ let parent = repo.root_path().parent().unwrap();+ assert!(!parent.join("repo.detached-a").exists());+ assert!(!parent.join("repo.detached-b").exists());+}+/// Prune skips locked worktrees#[rstest]fn test_prune_skips_locked(mut repo: TestRepo) {diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_current_worktree.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_current_worktree.snapindex e92f17a36..1b99b93df 100644--- a/tests/snapshots/integration__integration_tests__step_prune__prune_current_worktree.snap+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_current_worktree.snap@@ -47,4 +47,4 @@ exit_code: 0[36m◎ Removing [1mcurrent-merged[22m worktree & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m[33m▲[39m [33mCannot change directory — shell integration not installed[39m[2m↳[22m [2mTo enable automatic cd, run [4mwt config shell install[24m[22m-[32m✓[39m [32mPruned 1 worktree (with branch)[39m+[32m✓[39m [32mPruned 1 worktree & branch[39mdiff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_dry_run.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_dry_run.snapindex 872a85d49..627a1d008 100644--- a/tests/snapshots/integration__integration_tests__step_prune__prune_dry_run.snap+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_dry_run.snap@@ -21,6 +21,7 @@ info:LANG: CLC_ALL: CMOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""PATH: "[PATH]"PSModulePath: ""RUST_LOG: warn@@ -45,4 +46,4 @@ exit_code: 0----- stderr -----[2m○[22m [1mmerged-a[22m — same commit as main[2m○[22m [1mmerged-b[22m — same commit as main-[2m↳[22m [2m2 worktrees (with branches) would be removed (dry run)[22m+[2m↳[22m [2m2 worktrees & branches would be removed (dry run)[22mdiff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_dry_run_mixed_worktrees_and_branches.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_dry_run_mixed_worktrees_and_branches.snapindex 16997ca58..a39bb52f6 100644--- a/tests/snapshots/integration__integration_tests__step_prune__prune_dry_run_mixed_worktrees_and_branches.snap+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_dry_run_mixed_worktrees_and_branches.snap@@ -20,6 +20,7 @@ info:LANG: CLC_ALL: CMOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""PATH: "[PATH]"PSModulePath: ""RUST_LOG: warn@@ -45,4 +46,4 @@ exit_code: 0[2m○[22m [1mmerged-a[22m — same commit as main[2m○[22m [1mmerged-b[22m — same commit as main[2m○[22m [1morphan-integrated[22m (branch only) — same commit as main-[2m↳[22m [2m2 worktrees (with branches), 1 branch would be removed (dry run)[22m+[2m↳[22m [2m2 worktrees & branches, 1 branch would be removed (dry run)[22mdiff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_during_rebase.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_during_rebase.snapindex 2e32f752b..78affa194 100644--- a/tests/snapshots/integration__integration_tests__step_prune__prune_during_rebase.snap+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_during_rebase.snap@@ -45,4 +45,4 @@ exit_code: 0----- stderr -----[36m◎ Removing [1mmerged-wt[22m worktree & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m-[32m✓[39m [32mPruned 1 worktree (with branch)[39m+[32m✓[39m [32mPruned 1 worktree & branch[39mdiff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_min_age_passes.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_min_age_passes.snapindex 730521f72..c747a7651 100644--- a/tests/snapshots/integration__integration_tests__step_prune__prune_min_age_passes.snap+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_min_age_passes.snap@@ -20,6 +20,7 @@ info:LANG: CLC_ALL: CMOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""PATH: "[PATH]"PSModulePath: ""RUST_LOG: warn@@ -43,4 +44,4 @@ exit_code: 0----- stderr -----[2m○[22m [1mold-merged[22m — same commit as main-[2m↳[22m [2m1 worktree (with branch) would be removed (dry run)[22m+[2m↳[22m [2m1 worktree & branch would be removed (dry run)[22mdiff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_mixed_worktree_and_orphan_branch.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_mixed_worktree_and_orphan_branch.snapindex fde23b31c..196a4a13b 100644--- a/tests/snapshots/integration__integration_tests__step_prune__prune_mixed_worktree_and_orphan_branch.snap+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_mixed_worktree_and_orphan_branch.snap@@ -1,6 +1,5 @@---source: tests/integration_tests/step_prune.rs-assertion_line: 282info:program: wtargs:@@ -16,7 +15,7 @@ info:GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"GIT_CONFIG_SYSTEM: /dev/null- GIT_PAGER: ""+ GIT_EDITOR: ""GIT_TERMINAL_PROMPT: "0"HOME: "[TEST_HOME]"LANG: C@@ -47,4 +46,4 @@ exit_code: 0----- stderr -----[36m◎ Removing [1mmerged-mixed[22m worktree & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m[32m✓ Removed branch [1morphan-mixed[22m (same commit as [1mmain[22m,[39m [2m_[22m[32m)[39m-[32m✓[39m [32mPruned 1 worktree (with branch), 1 branch[39m+[32m✓[39m [32mPruned 1 worktree & branch, 1 branch[39mdiff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_multiple.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_multiple.snapindex 9b00ab266..842bd60f4 100644--- a/tests/snapshots/integration__integration_tests__step_prune__prune_multiple.snap+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_multiple.snap@@ -21,6 +21,7 @@ info:LANG: CLC_ALL: CMOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""PATH: "[PATH]"PSModulePath: ""RUST_LOG: warn@@ -46,4 +47,4 @@ exit_code: 0[36m◎ Removing [1mmerged-a[22m worktree & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m[36m◎ Removing [1mmerged-b[22m worktree & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m[36m◎ Removing [1mmerged-c[22m worktree & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m-[32m✓[39m [32mPruned 3 worktrees (with branches)[39m+[32m✓[39m [32mPruned 3 worktrees & branches[39mdiff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_removes_integrated_detached.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_removes_integrated_detached.snapindex 720cd1e50..69fbc2429 100644--- a/tests/snapshots/integration__integration_tests__step_prune__prune_removes_integrated_detached.snap+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_removes_integrated_detached.snap@@ -21,6 +21,7 @@ info:LANG: CLC_ALL: CMOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""PATH: "[PATH]"PSModulePath: ""RUST_LOG: warn@@ -45,4 +46,4 @@ exit_code: 0----- stderr -----[36m◎[39m [36mRemoving worktree @ [1m_REPO_.detached-integrated[22m in background (detached HEAD, no branch to delete)[39m[32m✓ Removed branch [1mdetached-integrated[22m (same commit as [1mmain[22m,[39m [2m_[22m[32m)[39m-[32m✓[39m [32mPruned 1 branch, 1 detached worktree[39m+[32m✓[39m [32mPruned 1 worktree, 1 branch[39mdiff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_removes_merged.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_removes_merged.snapindex 6d1dca9f3..03c26cc10 100644--- a/tests/snapshots/integration__integration_tests__step_prune__prune_removes_merged.snap+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_removes_merged.snap@@ -21,6 +21,7 @@ info:LANG: CLC_ALL: CMOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""PATH: "[PATH]"PSModulePath: ""RUST_LOG: warn@@ -44,4 +45,4 @@ exit_code: 0----- stderr -----[36m◎ Removing [1mmerged-branch[22m worktree & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m-[32m✓[39m [32mPruned 1 worktree (with branch)[39m+[32m✓[39m [32mPruned 1 worktree & branch[39mdiff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_removes_multiple_detached.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_removes_multiple_detached.snapnew file mode 100644index 000000000..6a61efa98--- /dev/null+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_removes_multiple_detached.snap@@ -0,0 +1,51 @@+---+source: tests/integration_tests/step_prune.rs+info:+ program: wt+ args:+ - step+ - prune+ - "--yes"+ - "--min-age=0s"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mRemoving worktree @ [1m_REPO_.detached-a[22m in background (detached HEAD, no branch to delete)[39m+[36m◎[39m [36mRemoving worktree @ [1m_REPO_.detached-b[22m in background (detached HEAD, no branch to delete)[39m+[32m✓ Removed branch [1mdetached-a[22m (same commit as [1mmain[22m,[39m [2m_[22m[32m)[39m+[32m✓ Removed branch [1mdetached-b[22m (same commit as [1mmain[22m,[39m [2m_[22m[32m)[39m+[32m✓[39m [32mPruned 2 worktrees, 2 branches[39mdiff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_skips_dirty.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_dirty.snapindex 4814d4d2a..54aa6928d 100644--- a/tests/snapshots/integration__integration_tests__step_prune__prune_skips_dirty.snap+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_dirty.snap@@ -21,6 +21,7 @@ info:LANG: CLC_ALL: CMOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""PATH: "[PATH]"PSModulePath: ""RUST_LOG: warn@@ -44,4 +45,4 @@ exit_code: 0----- stderr -----[36m◎ Removing [1mclean-merged[22m worktree & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m-[32m✓[39m [32mPruned 1 worktree (with branch)[39m+[32m✓[39m [32mPruned 1 worktree & branch[39mdiff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_skips_locked.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_locked.snapindex 6d1dca9f3..03c26cc10 100644--- a/tests/snapshots/integration__integration_tests__step_prune__prune_skips_locked.snap+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_locked.snap@@ -21,6 +21,7 @@ info:LANG: CLC_ALL: CMOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""PATH: "[PATH]"PSModulePath: ""RUST_LOG: warn@@ -44,4 +45,4 @@ exit_code: 0----- stderr -----[36m◎ Removing [1mmerged-branch[22m worktree & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m-[32m✓[39m [32mPruned 1 worktree (with branch)[39m+[32m✓[39m [32mPruned 1 worktree & branch[39mdiff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged.snapindex 5cedffea7..39020f9ae 100644--- a/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged.snap+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged.snap@@ -21,6 +21,7 @@ info:LANG: CLC_ALL: CMOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""PATH: "[PATH]"PSModulePath: ""RUST_LOG: warn@@ -44,4 +45,4 @@ exit_code: 0----- stderr -----[36m◎ Removing [1mmerged-one[22m worktree & branch in background (same commit as [1mmain[22m,[39m [2m_[22m[36m)[39m-[32m✓[39m [32mPruned 1 worktree (with branch)[39m+[32m✓[39m [32mPruned 1 worktree & branch[39mdiff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged_detached.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged_detached.snapindex 4c3459d61..4975d39ab 100644--- a/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged_detached.snap+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged_detached.snap@@ -21,6 +21,7 @@ info:LANG: CLC_ALL: CMOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""PATH: "[PATH]"PSModulePath: ""RUST_LOG: warn@@ -44,4 +45,4 @@ exit_code: 0----- stderr -----[2m○[22m [1mmerged-branch[22m — same commit as main-[2m↳[22m [2m1 worktree (with branch) would be removed (dry run)[22m+[2m↳[22m [2m1 worktree & branch would be removed (dry run)[22m