worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

picker alt-r removal skips pre-remove and post-remove hooks

Open worktrunk-bot opened this issue 8 months ago • 2 comments

Bug

Worktree removal via alt-r in the picker (wt switch TUI) skips pre-remove and post-remove hooks entirely.

The code at src/commands/picker/mod.rs:70 explicitly notes:

No output, no hooks, no cd directives — we're inside skim's TUI.

Impact

  • pre-remove hooks intended as safety checks (e.g., preventing removal of worktrees with uncommitted work) are bypassed
  • post-remove cleanup hooks (e.g., stopping services, cleaning up ports) never run

Context

Running hooks inside skim's TUI event loop is architecturally constrained — the main thread blocks skim, and hooks may produce output or require user interaction. However:

  1. pre-remove hooks could run before signaling skim to reload (they're blocking by design)
  2. post-remove hooks could be spawned in the background thread alongside the git operations

Suggestion

At minimum, run pre-remove hooks before the removal. If the hook fails, skip the removal and show a brief indicator. For post-remove, spawn in the background thread after execute_removal.

If hooks can't be supported, document this limitation in wt switch --help and the picker legend, not just as an inline code comment.

worktrunk-bot avatar Mar 24 '26 06:03 worktrunk-bot

@worktrunk-bot fix

max-sixty avatar Mar 24 '26 07:03 max-sixty

Fix in #1710.

The picker's background thread now runs pre-remove hooks (silently, with suppressed output) before execute_removal, and spawns post-remove hooks via spawn_background_hooks after. Pre-remove hook failure aborts the removal. Template variables match the normal wt remove flow.

Added run_hooks_silently() for TUI contexts where stderr output would corrupt skim's display — it runs each hook command, checks exit codes, and bails on first failure.

worktrunk-bot avatar Mar 24 '26 07:03 worktrunk-bot