Skip to content

feat(try-repo): add support for builtin and meta repos#1542

Draft
shaanmajid wants to merge 3 commits intoj178:masterfrom
shaanmajid:feat/try-repo-builtin-meta
Draft

feat(try-repo): add support for builtin and meta repos#1542
shaanmajid wants to merge 3 commits intoj178:masterfrom
shaanmajid:feat/try-repo-builtin-meta

Conversation

@shaanmajid
Copy link
Collaborator

@shaanmajid shaanmajid commented Feb 3, 2026

Add try-repo builtin and try-repo meta commands to test built-in and meta hooks without needing a git repository.

Changes:

  • Add strum crate for enum derives (EnumIter, EnumString, IntoStaticStr) (jk Use strum derives to reduce handwritten enum parsing and display #1541 added this before me :p)
  • Replace manual FromStr implementations with strum derives
  • Add HookRegistry trait to abstract over BuiltinHooks and MetaHooks
  • Implement try_special_repo<H: HookRegistry>() for generic handling
  • Add case-insensitive matching for "builtin" and "meta" keywords
  • Warn when --ref is used with special repos (ignored)
  • Add empty hooks check to try_git_repo for consistency
  • Add comprehensive integration tests for all new functionality

Closes #1521

@shaanmajid shaanmajid force-pushed the feat/try-repo-builtin-meta branch from f70af0c to 3eb9962 Compare February 3, 2026 04:15
@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

❌ Patch coverage is 97.65625% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.75%. Comparing base (c99a61e) to head (495826a).

Files with missing lines Patch % Lines
crates/prek/src/cli/try_repo.rs 97.29% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1542      +/-   ##
==========================================
+ Coverage   91.67%   91.75%   +0.08%     
==========================================
  Files          93       93              
  Lines       18333    18417      +84     
==========================================
+ Hits        16807    16899      +92     
+ Misses       1526     1518       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@prek-ci-bot
Copy link

prek-ci-bot bot commented Feb 3, 2026

📦 Cargo Bloat Comparison

Binary size change: +0.00% (23.7 MiB → 23.7 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size             Crate Name
 0.3%   0.8% 80.6KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 70.5KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.6% 65.6KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 51.2KiB annotate_snippets annotate_snippets::renderer::render::render
 0.2%   0.5% 50.5KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 45.1KiB              prek prek::run::{{closure}}
 0.2%   0.4% 43.4KiB              prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 41.1KiB              prek prek::cli::run::run::run::{{closure}}
 0.1%   0.3% 31.6KiB             prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 28.4KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 24.8KiB             prek? <prek::config::_::<impl serde_core::de::Deserialize for prek::config::Config>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 22.6KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 22.2KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 22.2KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.1KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.0KiB   cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.9KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 19.6KiB              prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.3KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
 0.1%   0.2% 19.3KiB        serde_json serde_json::value::de::<impl serde_core::de::Deserialize for serde_json::value::Value>::deserialize
38.4%  91.4%  9.1MiB                   And 20921 smaller methods. Use -n N to show more.
42.0% 100.0% 10.0MiB                   .text section size, the file size is 23.7MiB

Base Branch Results

 File  .text    Size             Crate Name
 0.3%   0.8% 78.2KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 70.4KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.6% 65.6KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 51.2KiB annotate_snippets annotate_snippets::renderer::render::render
 0.2%   0.5% 50.5KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 43.4KiB              prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 41.1KiB              prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 38.6KiB              prek prek::run::{{closure}}
 0.1%   0.3% 32.0KiB             prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 28.4KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 24.8KiB             prek? <prek::config::_::<impl serde_core::de::Deserialize for prek::config::Config>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 22.6KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 22.2KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 22.2KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.1KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.0KiB   cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.8KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 19.6KiB              prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.3KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
 0.1%   0.2% 19.3KiB     serde_saphyr? <serde_saphyr::de::YamlDeserializer as serde_core::de::Deserializer>::deserialize_any
38.4%  91.5%  9.1MiB                   And 20951 smaller methods. Use -n N to show more.
42.0% 100.0% 10.0MiB                   .text section size, the file size is 23.7MiB

@shaanmajid shaanmajid force-pushed the feat/try-repo-builtin-meta branch 2 times, most recently from a1bcd98 to d45ff40 Compare February 8, 2026 01:53
- Add HookRegistry trait with REPO_NAME constant and all_ids() method
- Use EnumIter, EnumString, and IntoStaticStr derives on BuiltinHooks
  and MetaHooks, replacing manual ALL_IDS constants and FromStr impls
- Refactor try_repo to use HookRegistry trait: extract try_special_repo
  generic over H: HookRegistry, RepoType enum for dispatch, and
  invoke_run helper to eliminate duplicated run() calls
- Make render_repo_config_toml accept Option<&str> for rev to support
  special repos that don't need a revision

Adding a new hook variant now only requires adding an enum variant —
the ID string, FromStr, and iteration are all derived via strum.
- Extract TryRepoContext struct to encapsulate store and tmp_dir setup,
  with run_with_config method handling config writing, printing, and
  run invocation — replacing the separate invoke_run helper
- Add empty-hooks bail to try_git_repo (matching try_special_repo) so
  selecting a nonexistent hook produces a clear error
- Normalize backslashes to forward slashes in rendered TOML repo paths
  so toml_edit produces consistent double-quoted strings on Windows
- Minor cleanups: inline temporary variables, shorten comments
Add comprehensive tests for try-repo with builtin and meta hook repos:
- Basic hook execution (trailing-whitespace, identity)
- Multiple hooks and all-hooks invocation
- Hook filtering with --skip
- Invalid hook ID error handling
- Case-insensitive repo name matching
- Config warning, meta skip, check-hooks-apply, check-useless-excludes

Extract test helpers: init_git_repo, setup_basic_context, and
filters_with_sha to reduce duplication across test cases.
@shaanmajid shaanmajid force-pushed the feat/try-repo-builtin-meta branch from d45ff40 to 495826a Compare February 8, 2026 01:59
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.

try-repo does not work with builtin

1 participant