Skip to content

refactor: deduplicate hook config resolution - #1512

Merged
max-sixty merged 2 commits into
mainfrom
dedup-hook-resolution
Mar 14, 2026
Merged

max-sixty merged 2 commits into
mainfrom
dedup-hook-resolution

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Both validate_switch_templates and the hook execution path independently derived which hooks apply and how to resolve user/project configs. If a new hook type or config source were added, both sites would need updating in lockstep (flagged in #1500 review).

Two changes:

  • Extract switch_post_hook_types() to share the hook-type list between approve_switch_hooks and validate_switch_templates
  • Make lookup_hook_configs pub(crate) and use it in commit.rs and step_commands.rs instead of manual field access (user_hooks.pre_commit / project_config.hooks.pre_commit)

Net -12 lines across 4 files.

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

max-sixty and others added 2 commits March 13, 2026 21:12
Extract switch_post_hook_types() to share the hook-type list between
approve_switch_hooks and validate_switch_templates. Make lookup_hook_configs
pub(crate) so validate_switch_templates uses the same config resolver as
the execution path instead of re-deriving it inline.

Co-Authored-By: Claude <[email protected]>
Replace manual field access (user_hooks.pre_commit / project_config.hooks.pre_commit)
with lookup_hook_configs() for consistency with the hook execution path.

Co-Authored-By: Claude <[email protected]>

@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.

Looks good — clean deduplication, net reduction in lines, no behavior change. Two observations:

  1. switch_post_hook_types is well-placed. Extracting the hook-type list into a single function is the right call — the previous inline duplication between approve_switch_hooks and validate_switch_templates was an easy place to introduce drift.

  2. lookup_hook_configs reuse in commit/squash is a nice win. The old manual field access (user_hooks.pre_commit / project_config.hooks.pre_commit) was a different spelling of the same logic — consolidating through lookup_hook_configs means a new hook type or config source only needs one update path.

No concerns — approve.

@max-sixty
max-sixty merged commit 15ffa05 into main Mar 14, 2026
21 checks passed
@max-sixty
max-sixty deleted the dedup-hook-resolution branch March 14, 2026 06:43
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