Skip to content

refactor(hooks): adopt TemplateVars in remaining call sites - #2481

Merged
max-sixty merged 2 commits into
mainfrom
hook-dispatch-unify
Apr 29, 2026
Merged

max-sixty merged 2 commits into
mainfrom
hook-dispatch-unify

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Follow-up to #2472. Four sites still built hook extra-vars by hand: commit.rs, step_commands::handle_squash, picker::do_removal, and hook_commands::build_manual_hook_extra_vars. They now use TemplateVars like the rest of the hook call sites — owning the strings and centralizing the worktree_path/worktree alias.

build_manual_hook_extra_vars is renamed to build_manual_hook_template_vars and returns TemplateVars so the two callers (run_hook, expand_command_template) can append CLI bindings or {{ args }} before materializing. Drops two redundant to_posix_path calls along the way.

Module docstring on template_vars.rs updated to reflect that the struct now covers all hook call sites, not just switch/merge.

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

`commit.rs`, `step_commands::handle_squash`, `picker::do_removal`, and
`hook_commands::build_manual_hook_extra_vars` were still building hook
extra-vars by hand with `Vec<(&str, &str)>` literals or `to_posix_path` +
tuple wrangling. They now use `TemplateVars` like the rest of the hook
call sites, which owns the strings and centralizes the
`worktree_path`/`worktree` alias.

`build_manual_hook_extra_vars` becomes `build_manual_hook_template_vars`
and returns `TemplateVars` so callers can extend with bindings (CLI
shorthand, `args` JSON) before materializing.

Co-Authored-By: Claude <[email protected]>
worktrunk-bot
worktrunk-bot previously approved these changes Apr 29, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codecov/patch is failing at 91.66% (44/48 added lines covered) vs the 96.73% project baseline. The misses are llvm-cov reformatting artifacts — same control flow as before, but the new shape exposes coverage points that the original lazy-iterator and one-line-call expressions hid. Specifics:

  • commit.rs:176 (template_vars = template_vars.with_target(target)) — the inside of the new if let Some(target) only fires when CommitOptions::target_branch == Some(_), which no test exercises. The pre-refactor .into_iter().map(...).collect() chain rendered the same uncovered path as a single covered line.
  • hook_commands.rs:129 (None => TemplateVars::new()) — the explicit None arm is unreachable in tests (default_branch is always Some in fixtures). The pre-refactor .into_iter().map(...).collect() collapsed both arms into one always-hit line.
  • commit.rs:233 and step_commands.rs:351 — the trailing )?; of the multi-line spawn_background_hooks(...) call. llvm-cov assigns this region to the ? error-propagation branch, which fires 0 times when the call succeeds; the pre-refactor one-line call had no separate region.

Suggestions below collapse each to a single expression, restoring the prior coverage shape. Fixing all four lines should bring patch coverage to 100%.

Comment thread src/commands/commit.rs Resolved
Comment thread src/commands/commit.rs Resolved
Comment thread src/commands/step_commands.rs Resolved
Comment thread src/commands/hook_commands.rs Resolved
@worktrunk-bot
worktrunk-bot dismissed their stale review April 29, 2026 23:44

codecov/patch is failing — see follow-up review for the four uncovered lines and inline fixes.

Auto-reviewer flagged 4 codecov misses on the previous commit — all
artifacts of llvm-cov region splitting on the new multi-line shapes
rather than real coverage gaps. Collapsing to single expressions
restores the pre-refactor coverage shape:

- `commit.rs::commit`: `if let` over `target_branch` → `map_or_else`
  (one expression covers both arms).
- `hook_commands.rs::build_manual_hook_template_vars`: same for the
  `default_branch` match arm.
- `commit.rs` and `step_commands.rs::handle_squash`: bind
  `template_vars.as_extra_vars()` to a local before calling
  `spawn_background_hooks`, so the call fits on one line and llvm-cov
  doesn't split out the trailing `)?;` as an unhit error-propagation
  region.

No behavior change.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 6701cc8 into main Apr 29, 2026
31 of 33 checks passed
@max-sixty
max-sixty deleted the hook-dispatch-unify branch April 29, 2026 23:58
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