Repository navigation
refactor(hooks): dedup background-hook entry points around HookAnnouncer - #2477
Merged
Merged
Conversation
Make `run_hooks_background` `pub(crate)` (only ever called in-crate), fold the `None` branch in `spawn_hooks_after_remove` into a local `HookAnnouncer`, and reimplement `spawn_background_hooks` on top of `HookAnnouncer::register`/`flush`. After this, `run_hooks_background` is the internal primitive behind `HookAnnouncer::flush`; the only remaining direct caller is `handle_switch::spawn_switch_background_hooks`, which is owned by the in-flight announcer migration. No behavior change. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
approved these changes
Apr 29, 2026
max-sixty
added a commit
that referenced
this pull request
Apr 30, 2026
…cer (#2482) Extends the `HookAnnouncer` coordinator (introduced in #2457, refined in #2477) to more hot paths so multi-phase background hooks share a single `◎ Running …` line. **Migrated sites:** - `wt switch --create` — post-switch + post-start (`spawn_switch_background_hooks` in `handle_switch.rs`). - `wt merge` — auto-commit (when dirty) + post-remove + post-switch + post-merge. - `wt merge --squash` — post-commit (from squash) + post-remove + post-switch + post-merge. **Plumbing:** `CommitOptions::commit` and `handle_squash` gained an optional `&mut HookAnnouncer<'_>` parameter. `handle_merge` constructs one announcer early and threads it through the commit, squash, and remove paths; `flush()` runs once at the end. Standalone `wt commit` / `wt step squash` pass `None` and self-announce as before. **No new abstractions** — the `Some` arm calls `extend`, the `None` arm calls `run_hooks_background`, mirroring the existing precedent in `output/handlers.rs::spawn_hooks_after_remove`. As a follow-on, `spawn_background_hooks` (whose only caller after migration was `picker::do_removal`, gated `#[cfg(unix)]`) is dropped and the picker's call site is inlined to match — fixing a Windows dead-code build error and unifying all four single-shot post-hook sites on the same shape. **Test coverage:** new `test_merge_squash_combines_post_commit_post_remove_post_switch_post_merge` and `test_merge_auto_commit_combines_post_commit_post_remove_post_switch_post_merge` snapshot the combined four-phase announce line for both squash and non-squash auto-commit paths. Existing `test_merge_combines_post_remove_post_switch_post_merge`, `test_merge_drops_pending_hooks_when_post_merge_fails`, and `test_switch_combined_post_switch_and_post_start_hooks` remain green. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Apr 30, 2026
Builds on #2477 and #2482. Drops the `Option<&mut HookAnnouncer<'_>>` plumbing through `commit.rs::commit`, `step_commands::handle_squash`, `output/handlers.rs::handle_remove_output` (and its four sub-handlers), and the multi-target prune loop in `step_commands::step_prune`. Each function now takes `&mut HookAnnouncer<'_>` unconditionally — the if/else around \"share with caller's announcer or self-announce\" is gone. Standalone callers (`wt commit`, `wt step squash`, `wt remove`, `wt step prune`, `wt switch` picker post-remove) construct a local announcer and flush right after; multi-phase callers (`wt merge`) keep their existing single-announcer-per-command pattern. `run_hooks_background` is now a module-private helper of `HookAnnouncer::flush` (was `pub(crate)`). `hook_commands::run_post_hook` also routes through `HookAnnouncer`, so `flush` is the only path that reaches the announce/spawn primitive. `RemovedWorktreeOutputContext` loses its now-redundant `show_branch_in_hooks` field — callers configure the announcer directly when constructing it. No behavior change: combined announce lines, log paths, `show_branch` semantics for batch contexts (prune, multi-target remove), and exit codes are all unchanged. Existing snapshots and the full integration suite (3399 tests) pass; `cargo run -- hook pre-merge --yes` is green. > _This was written by Claude Code on behalf of @max-sixty_ Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make
run_hooks_backgroundpub(crate)(only ever called in-crate), fold theNonebranch inspawn_hooks_after_removeinto a localHookAnnouncer, and reimplementspawn_background_hookson top ofHookAnnouncer::register/flush.After this,
run_hooks_backgroundis the internal primitive behindHookAnnouncer::flush; the only remaining direct caller ishandle_switch::spawn_switch_background_hooks, which a separate in-flight migration owns. Once switch and the commit/squash sites move ontoHookAnnouncer,spawn_background_hooksand theOption<&mut HookAnnouncer>plumbing inoutput/handlers.rscan be retired.No behavior change — combined announce line, log paths,
show_branchsemantics, and exit codes are unchanged. Existing snapshots and the full integration suite pass.