Repository navigation
refactor: deduplicate hook config resolution - #1512
Merged
Merged
Conversation
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
approved these changes
Mar 14, 2026
worktrunk-bot
left a comment
Collaborator
There was a problem hiding this comment.
Looks good — clean deduplication, net reduction in lines, no behavior change. Two observations:
-
switch_post_hook_typesis well-placed. Extracting the hook-type list into a single function is the right call — the previous inline duplication betweenapprove_switch_hooksandvalidate_switch_templateswas an easy place to introduce drift. -
lookup_hook_configsreuse 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 throughlookup_hook_configsmeans a new hook type or config source only needs one update path.
No concerns — approve.
1 task
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.
Both
validate_switch_templatesand 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:
switch_post_hook_types()to share the hook-type list betweenapprove_switch_hooksandvalidate_switch_templateslookup_hook_configspub(crate)and use it incommit.rsandstep_commands.rsinstead of manual field access (user_hooks.pre_commit/project_config.hooks.pre_commit)Net -12 lines across 4 files.