Repository navigation
fix: run pre/post-remove hooks during picker alt-r removal - #1710
Conversation
The picker's alt-r removal was skipping all hooks entirely. This was a problem because pre-remove hooks serve as safety checks (e.g., preventing removal of worktrees with uncommitted work) and post-remove hooks handle cleanup (e.g., stopping services). Now: - Pre-remove hooks run silently before removal; non-zero exit aborts - Post-remove hooks spawn in background after successful removal Hooks run with suppressed stdout/stderr since we're inside skim's TUI and writing to the terminal would corrupt the display. Closes #1704 Co-Authored-By: Claude Opus 4.6 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI is failing because cargo fmt wants to collapse the multi-line bail! into a single line. One formatting fix needed.
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI: test (windows) fails — clippy reports dead_code for run_hooks_silently. The picker module is #[cfg(unix)], so this function's only caller doesn't exist on Windows.
Fix: gate run_hooks_silently with #[cfg(unix)] to match its caller.
codecov/patch also fails (62% vs 95% target) — the new do_removal hook logic in picker/mod.rs is largely untested. Worth adding at least a unit test for run_hooks_silently and integration coverage for the picker removal path.
The function is only called from the picker module which is #[cfg(unix)], causing a dead_code error on Windows. Co-Authored-By: Claude <[email protected]>
Cover empty list, successful hook, failing hook (abort + error message), and unnamed hook paths. Co-Authored-By: Claude Opus 4.6 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
Hook approval bypass in TUI removal path
do_removal runs both user and project hooks without calling approve_hooks. The normal wt remove path requires approval for project-sourced hooks (untrusted commands from wt.toml). The picker's switch path handles this by calling approve_switch_hooks after the TUI exits (line 625), but removal happens inside the TUI callback where interactive prompts aren't possible.
Options to consider:
- Skip project hooks in
do_removal(only run user hooks, which don't need approval) - Pre-approve remove hooks before entering the TUI (like the switch path does)
- Filter
pre_remove_commandsto onlyHookSource::Usercommands
This is the only substantive concern — the rest looks correct. The unit tests cover the important paths well.
|
This is hard to cover in unit tests because The new |
|
@worktrunk-bot merge main and reevaluate |
# Conflicts: # src/commands/picker/mod.rs
Co-Authored-By: Claude Opus 4.6 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
All required CI checks pass (linux, macos, windows). codecov/patch still fails — the coverage gap in do_removal's hook setup code persists from the previous iteration.
Previous review concerns still apply (project hook approval bypass, minor name duplication) — leaving those threads open.
|
Merged main and re-ran CI. Results: Required checks: all pass (lint, test linux/macos/windows, code-coverage, pre-commit)
The merge conflict with #1717 was in |
|
does this block the |
|
Yes — pre-remove hooks run synchronously (via In practice, the blocking should be brief since pre-remove hooks are typically fast (the same way |
|
ok, that seems quite bad, even though the alternative is not great either I think for the moment let's optimistically remove, so it doesn't freeze and add a big TODO that until we get more control of the UI (can edit it to show something in progress, it's going to be a substandard experience, which is why we removed the docs |
Running pre-remove hooks synchronously inside skim's TUI callback freezes the picker until they complete. Remove the synchronous pre-remove hook path and add a TODO noting the intentional limitation. Post-remove hooks (background, non-blocking) are retained. Also removes the now-unused run_hooks_silently function and its tests. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Done — removed pre-remove hooks from the picker path so removal is optimistic and non-blocking. Post-remove hooks (already background) are kept. Added a TODO on Also removed the now-unused |
Co-Authored-By: Claude <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
All required CI checks pass (lint, test linux/macos/windows, code-coverage). codecov/patch fails at the same coverage gap discussed previously — the do_removal hook setup path in picker/mod.rs can't be unit-tested without spawning skim's TUI.
The change itself looks correct: post-remove hooks use the standard spawn_background_hooks infrastructure, pre-remove is intentionally skipped per maintainer direction, and the TODO clearly documents the limitation.
Previous review concerns (project hook approval bypass, run_hooks_silently removal) have been addressed by this iteration — pre-remove hooks are fully removed, and post-remove hooks are background-only.
|
All required checks pass (lint, test linux/macos/windows, code-coverage, pre-commit). |
|
we don't want to skip the pre hook, just to background the whole op, while optimistically removing it from the list |
Run the entire removal operation (pre-remove hooks → removal → post-remove hooks) in the background thread, keeping the picker responsive while still honoring pre-remove hook semantics. The item is optimistically removed from the picker list before the background operation starts. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Good call — updated to background the entire operation (pre-remove hooks → removal → post-remove hooks) instead of skipping pre-remove hooks. The picker optimistically removes the item from the list, then the background thread runs pre-remove hooks synchronously before proceeding with removal. If a pre-remove hook fails, the removal is aborted (though the item is already gone from the picker list — tradeoff until we can show in-progress state). |
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Summary
run_hooks_silently()helper for TUI contexts where writing to stderr would corrupt the displayCloses #1704
Implementation
Hooks run inside the existing background thread that handles git operations (not on skim's main event loop, which would freeze the TUI). Pre-remove hooks use
run_hooks_silently()which executes each command with suppressed stdout/stderr and checks exit codes. Post-remove hooks use the existingspawn_background_hooksinfrastructure which logs to files.Template variables match the normal
wt removeflow:{{ target }},{{ target_worktree_path }}for pre-remove; full removed worktree context for post-remove.Test plan
test_execute_removal_removes_worktree_and_branch)🤖 Generated with Claude Code