Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix: clean up prune output — silent skip, no noise (#1236)

Maximilian Roos921a5afadfaf
diff --git a/src/commands/merge.rs b/src/commands/merge.rs
index 417f283fa..0fdd90552 100644
--- a/src/commands/merge.rs
+++ b/src/commands/merge.rs
@@ -269,7 +269,7 @@ pub fn handle_merge(opts: MergeOptions<'_>) -> anyhow::Result<()> {
};
// Run hooks during merge removal (pass through verify flag)
// Approval was handled at the gate (collect_merge_commands)
- crate::output::handle_remove_output(&remove_result, true, verify)?;
+ crate::output::handle_remove_output(&remove_result, true, verify, false)?;
} else {
// Worktree preserved - show reason (priority: main worktree > on target > --no-remove flag)
let message = if in_main {
diff --git a/src/commands/step_commands.rs b/src/commands/step_commands.rs
index d39598df1..1a209aaf9 100644
--- a/src/commands/step_commands.rs
+++ b/src/commands/step_commands.rs
@@ -1419,15 +1419,13 @@ pub fn step_prune(dry_run: bool, yes: bool, min_age: &str, foreground: bool) ->
config,
) {
Ok(plan) => plan,
- Err(e) => {
- eprintln!(
- "{}",
- warning_message(format!("Skipping {}: {e:#}", candidate.label))
- );
+ Err(_) => {
+ // prepare_worktree_removal is the gate: if the worktree can't
+ // be removed (dirty, locked, etc.), it's simply not selected.
return Ok(false);
}
};
- handle_remove_output(&plan, !foreground, run_hooks)?;
+ handle_remove_output(&plan, !foreground, run_hooks, true)?;
Ok(true)
}
diff --git a/src/main.rs b/src/main.rs
index 1d63ee259..b01f591d7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -842,7 +842,7 @@ fn main() {
// "Approve at the Gate": approval happens AFTER validation passes
let run_hooks = verify && approve_remove(yes)?;
- handle_remove_output(&result, background, run_hooks)
+ handle_remove_output(&result, background, run_hooks, false)
} else {
// Multi-worktree removal: validate ALL first, then approve, then execute
// This supports partial success - some may fail validation while others succeed.
@@ -961,17 +961,17 @@ fn main() {
// Phase 3: Execute all validated plans
// Remove other worktrees first
for result in plans_others {
- handle_remove_output(&result, background, run_hooks)?;
+ handle_remove_output(&result, background, run_hooks, false)?;
}
// Handle branch-only cases
for result in plans_branch_only {
- handle_remove_output(&result, background, run_hooks)?;
+ handle_remove_output(&result, background, run_hooks, false)?;
}
// Remove current worktree last (if it was in the list)
if let Some(result) = plan_current {
- handle_remove_output(&result, background, run_hooks)?;
+ handle_remove_output(&result, background, run_hooks, false)?;
}
// Exit with failure if any validation errors occurred
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index 6ea9d25fc..be9011160 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -626,10 +626,13 @@ pub fn execute_user_command(command: &str, display_path: Option<&Path>) -> anyho
/// Handle output for a remove operation
///
/// Approval is handled at the gate (command entry point), not here.
+/// When `quiet` is true (prune context), suppresses informational messages
+/// like "No worktree found for branch X" that are noise in batch operations.
pub fn handle_remove_output(
result: &RemoveResult,
background: bool,
verify: bool,
+ quiet: bool,
) -> anyhow::Result<()> {
match result {
RemoveResult::RemovedWorktree {
@@ -661,15 +664,19 @@ pub fn handle_remove_output(
branch_name,
deletion_mode,
pruned,
- } => handle_branch_only_output(branch_name, *deletion_mode, *pruned),
+ } => handle_branch_only_output(branch_name, *deletion_mode, *pruned, quiet),
}
}
/// Handle output for BranchOnly removal (branch exists but no worktree)
+///
+/// When `quiet` is true, suppresses the "No worktree found for branch X"
+/// info line for non-pruned cases (noise in prune/batch context).
fn handle_branch_only_output(
branch_name: &str,
deletion_mode: BranchDeletionMode,
pruned: bool,
+ quiet: bool,
) -> anyhow::Result<()> {
let branch_info = if pruned {
cformat!("Worktree directory missing for <bold>{branch_name}</>; pruned")
@@ -731,7 +738,9 @@ fn handle_branch_only_output(
))
);
} else {
- eprintln!("{}", info_message(&branch_info));
+ if !quiet {
+ eprintln!("{}", info_message(&branch_info));
+ }
eprintln!(
"{}",
FormattedMessage::new(cformat!(
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_orphan_branches.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_orphan_branches.snap
index 93df5af9f..a5d59bdd9 100644
--- a/tests/snapshots/integration__integration_tests__step_prune__prune_orphan_branches.snap
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_orphan_branches.snap
@@ -42,8 +42,6 @@ exit_code: 0
----- stdout -----
----- stderr -----
-○ No worktree found for branch orphan-a
✓ Removed branch orphan-a (same commit as main, _)
-○ No worktree found for branch orphan-b
✓ Removed branch orphan-b (same commit as main, _)
✓ Pruned 2 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 0248952e8..720cd1e50 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
@@ -44,6 +44,5 @@ exit_code: 0
----- stderr -----
◎ Removing worktree @ _REPO_.detached-integrated in background (detached HEAD, no branch to delete)
-○ No worktree found for branch detached-integrated
✓ Removed branch detached-integrated (same commit as main, _)
✓ Pruned 1 branch, 1 detached worktree
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 28356057b..4814d4d2a 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
@@ -44,6 +44,4 @@ exit_code: 0
----- stderr -----
◎ Removing clean-merged worktree & branch in background (same commit as main, _)
-▲ Skipping dirty-merged: ✗ Cannot remove worktree: dirty-merged has uncommitted changes
-↳ Commit or stash changes first, or to lose uncommitted changes, run wt remove --force dirty-merged
✓ Pruned 1 worktree (with branch)