Skip to content

Match files/exclude filter against relative path of nested project#1624

Merged
j178 merged 3 commits intoj178:masterfrom
soraxas:fix/workspace-relative-path
Feb 12, 2026
Merged

Match files/exclude filter against relative path of nested project#1624
j178 merged 3 commits intoj178:masterfrom
soraxas:fix/workspace-relative-path

Conversation

@soraxas
Copy link
Contributor

@soraxas soraxas commented Feb 11, 2026

Previously, in a setup that looks like

.
├── .pre-commit-config.yaml        # setting A (root)
└── mynestedrepo
    ├── .pre-commit-config.yaml    # setting B (nested repo)
    └── tobeexcluded
        └── nodonttrackthis.md

mynestedrepo is a nested folder using the workspace feature with a nested .pre-commit-config.yaml. Ideally (especially in a monorepo setup), it shouldn't need to care about any folder level above it.

Previously, if mynestedrepo/.pre-commit-config.yaml B contains

exclude: (^tobeexcluded/)
repos:
  ...

one would expect mynestedrepo/tobeexcluded to be excluded. However, the path passed from the filename filter previously uses the full path, so it will still modify the nodonttrackthis.md file even though it should be excluded.

Currently, the inner settings exclude pattern needs to specify either (^mynestedrepo/tobeexcluded/) (which is not ideal if we want the inner repo to be agnoistic to any folder above it) or (tobeexcluded/) (which risk excluding some wanted folder if the exclude pattern is generic).

This PR makes it so that only the inner relative path is passed to the filename filter.


i.e., instead of passing
mynestedrepo/tobeexcluded/nodonttrackthis.md
we pass
tobeexcluded/nodonttrackthis.md
to the inner project instead

@soraxas soraxas requested a review from j178 as a code owner February 11, 2026 14:17
Copilot AI review requested due to automatic review settings February 11, 2026 14:17
@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.80%. Comparing base (031e53b) to head (7abf591).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1624      +/-   ##
==========================================
+ Coverage   91.73%   91.80%   +0.06%     
==========================================
  Files          96       96              
  Lines       18630    18941     +311     
==========================================
+ Hits        17091    17389     +298     
- Misses       1539     1552      +13     

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adjusts how prek applies per-project include/exclude patterns in a workspace so that nested projects evaluate patterns against paths relative to their own project root (not the workspace root), matching expected monorepo behavior.

Changes:

  • Strip the project’s relative_path prefix before applying project-level files/exclude filters.
  • Add an integration snapshot test asserting nested-project excludes are evaluated against project-relative paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
crates/prek/src/cli/run/filter.rs Updates project-level filename filtering to apply patterns to paths relative to each project root.
crates/prek/tests/workspace.rs Adds a regression test validating nested workspace exclude behavior is project-relative.

@prek-ci-bot
Copy link

prek-ci-bot bot commented Feb 11, 2026

📦 Cargo Bloat Comparison

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

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size             Crate Name
 0.3%   0.7% 71.3KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.6% 66.6KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 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.6KiB              prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 39.0KiB              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.5KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 25.0KiB             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.8KiB      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% 21.1KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.0KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 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.3KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
 0.1%   0.2% 19.2KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.1KiB              prek prek::hook::HookBuilder::build::{{closure}}
38.6%  91.6%  9.2MiB                   And 21048 smaller methods. Use -n N to show more.
42.1% 100.0% 10.0MiB                   .text section size, the file size is 23.8MiB

Base Branch Results

 File  .text    Size             Crate Name
 0.3%   0.7% 71.3KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.6% 66.4KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 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.2KiB              prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 39.0KiB              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.5KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 25.0KiB             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.8KiB      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% 21.1KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.4KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 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.3KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
 0.1%   0.2% 19.2KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.0KiB              prek prek::hook::HookBuilder::build::{{closure}}
38.6%  91.6%  9.2MiB                   And 21033 smaller methods. Use -n N to show more.
42.1% 100.0% 10.0MiB                   .text section size, the file size is 23.8MiB

@j178 j178 self-assigned this Feb 12, 2026
@j178 j178 added the bug Something isn't working label Feb 12, 2026
@j178 j178 changed the title Pass relative path to nested workspace Match files/exclude filter against relative path of nested workspace Feb 12, 2026
@j178 j178 changed the title Match files/exclude filter against relative path of nested workspace Match files/exclude filter against relative path of nested project Feb 12, 2026
Copy link
Owner

@j178 j178 left a comment

Choose a reason for hiding this comment

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

Thanks!

@j178 j178 merged commit eb80de7 into j178:master Feb 12, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants