Skip to content

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.rs
index 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.rs
index 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.rs
index 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.snap
index 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
◎ Removing current-merged worktree & branch in background (same commit as main, _)
▲ Cannot change directory — shell integration not installed
↳ To enable automatic cd, run wt config shell install
-✓ Pruned 1 worktree (with branch)
+✓ Pruned 1 worktree & branch
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_dry_run.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_dry_run.snap
index 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: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
@@ -45,4 +46,4 @@ exit_code: 0
----- stderr -----
○ merged-a — same commit as main
○ merged-b — same commit as main
-↳ 2 worktrees (with branches) would be removed (dry run)
+↳ 2 worktrees & branches would be removed (dry run)
diff --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.snap
index 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: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
@@ -45,4 +46,4 @@ exit_code: 0
○ merged-a — same commit as main
○ merged-b — same commit as main
○ orphan-integrated (branch only) — same commit as main
-↳ 2 worktrees (with branches), 1 branch would be removed (dry run)
+↳ 2 worktrees & branches, 1 branch would be removed (dry run)
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_during_rebase.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_during_rebase.snap
index 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 -----
◎ Removing merged-wt worktree & branch in background (same commit as main, _)
-✓ Pruned 1 worktree (with branch)
+✓ Pruned 1 worktree & branch
diff --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.snap
index 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: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
@@ -43,4 +44,4 @@ exit_code: 0
----- stderr -----
○ old-merged — same commit as main
-↳ 1 worktree (with branch) would be removed (dry run)
+↳ 1 worktree & branch would be removed (dry run)
diff --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.snap
index 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: 282
info:
program: wt
args:
@@ -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 -----
◎ Removing merged-mixed worktree & branch in background (same commit as main, _)
✓ Removed branch orphan-mixed (same commit as main, _)
-✓ Pruned 1 worktree (with branch), 1 branch
+✓ Pruned 1 worktree & branch, 1 branch
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_multiple.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_multiple.snap
index 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: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
@@ -46,4 +47,4 @@ exit_code: 0
◎ Removing merged-a worktree & branch in background (same commit as main, _)
◎ Removing merged-b worktree & branch in background (same commit as main, _)
◎ Removing merged-c worktree & branch in background (same commit as main, _)
-✓ Pruned 3 worktrees (with branches)
+✓ Pruned 3 worktrees & branches
diff --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.snap
index 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: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
@@ -45,4 +46,4 @@ exit_code: 0
----- stderr -----
◎ Removing worktree @ _REPO_.detached-integrated in background (detached HEAD, no branch to delete)
✓ Removed branch detached-integrated (same commit as main, _)
-✓ Pruned 1 branch, 1 detached worktree
+✓ Pruned 1 worktree, 1 branch
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_removes_merged.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_removes_merged.snap
index 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: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
@@ -44,4 +45,4 @@ exit_code: 0
----- stderr -----
◎ Removing merged-branch worktree & branch in background (same commit as main, _)
-✓ Pruned 1 worktree (with branch)
+✓ Pruned 1 worktree & branch
diff --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.snap
new file mode 100644
index 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 -----
+◎ Removing worktree @ _REPO_.detached-a in background (detached HEAD, no branch to delete)
+◎ Removing worktree @ _REPO_.detached-b in background (detached HEAD, no branch to delete)
+✓ Removed branch detached-a (same commit as main, _)
+✓ Removed branch detached-b (same commit as main, _)
+✓ Pruned 2 worktrees, 2 branches
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_skips_dirty.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_dirty.snap
index 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: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
@@ -44,4 +45,4 @@ exit_code: 0
----- stderr -----
◎ Removing clean-merged worktree & branch in background (same commit as main, _)
-✓ Pruned 1 worktree (with branch)
+✓ Pruned 1 worktree & branch
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_skips_locked.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_locked.snap
index 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: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
@@ -44,4 +45,4 @@ exit_code: 0
----- stderr -----
◎ Removing merged-branch worktree & branch in background (same commit as main, _)
-✓ Pruned 1 worktree (with branch)
+✓ Pruned 1 worktree & branch
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_skips_unmerged.snap
index 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: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
@@ -44,4 +45,4 @@ exit_code: 0
----- stderr -----
◎ Removing merged-one worktree & branch in background (same commit as main, _)
-✓ Pruned 1 worktree (with branch)
+✓ Pruned 1 worktree & branch
diff --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.snap
index 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: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
@@ -44,4 +45,4 @@ exit_code: 0
----- stderr -----
○ merged-branch — same commit as main
-↳ 1 worktree (with branch) would be removed (dry run)
+↳ 1 worktree & branch would be removed (dry run)