Skip to content

Add repo: self support for consuming own hooks #1601

Draft
shaanmajid wants to merge 4 commits intomasterfrom
feat/repo-self
Draft

Add repo: self support for consuming own hooks #1601
shaanmajid wants to merge 4 commits intomasterfrom
feat/repo-self

Conversation

@shaanmajid
Copy link
Collaborator

Closes #1598

Allow projects that publish hooks via `.pre-commit-hooks.yaml` to
consume their own hooks with `repo: self`, avoiding redundant
`repo: local` definitions.

Add a 5th repo type `SelfRepo` using `"self"` as the sentinel value.
Hooks use `RemoteHook` shape (only `id` required, rest optional
overrides). At init time, reads `.pre-commit-hooks.yaml` from the
project root (no cloning) and resolves hooks using the existing
manifest-lookup + override pattern. Exposes the project root as
`repo_path()` for language installers.

Handles `repo: self` across all code paths: config parsing,
runtime hook resolution, workspace init, JSON schema, auto-update
(skip), cache GC (track hook envs), tab completion, meta hooks
validation, and language runner dispatch.
Test system hook execution with file filtering, config overrides
(name, args), missing manifest error, unknown hook ID error, and
cache GC retention of self-repo hook environments.
Add `repo: self` section to configuration.md with TOML and YAML
examples. Update the prek-specific extensions list in diff.md.
@shaanmajid shaanmajid requested a review from j178 as a code owner February 7, 2026 23:59
@codecov
Copy link

codecov bot commented Feb 8, 2026

Codecov Report

❌ Patch coverage is 87.57764% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.65%. Comparing base (c99a61e) to head (52e586c).

Files with missing lines Patch % Lines
crates/prek/src/cli/cache_gc.rs 70.83% 7 Missing ⚠️
crates/prek/src/cli/completion.rs 0.00% 4 Missing ⚠️
crates/prek/src/config.rs 95.12% 4 Missing ⚠️
crates/prek/src/hook.rs 89.47% 2 Missing ⚠️
crates/prek/src/workspace.rs 90.00% 2 Missing ⚠️
crates/prek/src/hooks/meta_hooks.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1601      +/-   ##
==========================================
- Coverage   91.67%   91.65%   -0.02%     
==========================================
  Files          93       93              
  Lines       18333    18482     +149     
==========================================
+ Hits        16807    16940     +133     
- Misses       1526     1542      +16     

☔ 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 8, 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% 78.2KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 74.6KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.7% 72.3KiB              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.9KiB              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% 42.0KiB              prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 38.5KiB              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% 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.4KiB              prek prek::hooks::meta_hooks::check_hooks_apply::{{closure}}
 0.1%   0.2% 19.4KiB              prek prek::hooks::meta_hooks::check_hooks_apply::{{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.4%  9.1MiB                   And 20916 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

The INSTA_FILTERS entry for normalizing os error messages never worked:
it matched `Caused by:` (capital C) but prek uses `caused by:`. Replace
the broken greedy pattern with a targeted substitution that swaps only
the Windows-specific `The system cannot find the file specified.` with
the Unix `No such file or directory`, leaving surrounding context intact.
@shaanmajid shaanmajid changed the title feat: add repo: self support for consuming own hooks Add repo: self support for consuming own hooks Feb 8, 2026
@shaanmajid shaanmajid marked this pull request as draft February 8, 2026 02:12
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.

Add a repo: self option to allow easy consumption of hooks defined inside .pre-commit-hooks.yaml

1 participant