Skip to content

refactor(hooks): dedup background-hook entry points around HookAnnouncer - #2477

Merged
max-sixty merged 1 commit into
mainfrom
hooks-dedup
Apr 29, 2026
Merged

max-sixty merged 1 commit into
mainfrom
hooks-dedup

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

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 a separate in-flight migration owns. Once switch and the commit/squash sites move onto HookAnnouncer, spawn_background_hooks and the Option<&mut HookAnnouncer> plumbing in output/handlers.rs can be retired.

No behavior change — combined announce line, log paths, show_branch semantics, and exit codes are unchanged. Existing snapshots and the full integration suite pass.

This was written by Claude Code on behalf of @max-sixty

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]>
@max-sixty
max-sixty merged commit d719695 into main Apr 29, 2026
25 checks passed
@max-sixty
max-sixty deleted the hooks-dedup branch April 29, 2026 21:56
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants