Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 28, 2025

Users were unaware that .gitignore files are already respected during workspace discovery, leading to unnecessary duplication in .prekignore files.

Changes

  • Documentation: Updated docs/workspace.md to clarify that prek respects .gitignore, .git/info/exclude, and global gitignore by default via the ignore crate
  • Documentation: Explained that .prekignore is only needed for additional exclusions beyond .gitignore
  • Test: Added gitignore_respected test to verify that gitignored directories (e.g., node_modules, target) are excluded from workspace discovery

Context

The ignore::WalkBuilder used for workspace discovery already honors all standard git ignore patterns by default. No code changes were needed—only documentation to surface this behavior.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek run -v (dns block)
  • mirrors.aliyun.com
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek run (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek run project2/ (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek run --skip project2/ (dns block)
  • mirrors.cloud.tencent.com
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek run (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek run project2/ (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek install-hooks (dns block)
  • notexistentatallnevergonnahappen.com
    • Triggering command: /usr/lib/git-core/git-remote-https origin REDACTED (dns block)
  • pypi.tuna.tsinghua.edu.cn
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek run (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek run project2/ (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek run --skip project2/ (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Don't discover prek workspaces in .gitignored directories</issue_title>
<issue_description>

- `prek` supports reading `.prekignore` files (following the same syntax rules as `.gitignore`) to exclude specific directories from workspace discovery. Like `.gitignore`, `.prekignore` files can be placed anywhere in the workspace and apply to their directory and all subdirectories. This works similarly to the `--skip` option but is configured via files.

  • prek supports reading .prekignore files (following the same syntax rules as .gitignore) to exclude specific directories from workspace discovery. Like .gitignore, .prekignore files can be placed anywhere in the workspace and apply to their directory and all subdirectories. This works similarly to the --skip option but is configured via files.

would be nice if prek excluded any folders in .gitignore from workspace discovery. avoids the need for another config file in many cases. i imagine .prekignore would often end up being a subset of .gitignore (probably containing all the directories in .gitignore but not specific ignored files or file globs). a lot of users would be saved the trouble of having to duplicate their ignored directories by reading .gitignore directly.

if both .gitignore and .prekignore are present, there's the question of whether prek should compute their superset or just disregard .gitignore in that case. i think it disregarding .gitignore if a .prekignore is found makes far more sense</issue_description>

Comments on the Issue (you are @copilot in this section)

@j178 `prek` uses [`ignore`](https://docs.rs/ignore/latest/ignore/struct.WalkBuilder.html), so > By default, all ignore files found are respected. This includes .ignore, .gitignore, .git/info/exclude and even your global gitignore globs, usually found in $XDG_CONFIG_HOME/git/ignore.

I’ll update the docs to mention that.</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: j178 <10510431+j178@users.noreply.github.com>
@j178 j178 added the documentation Improvements or additions to documentation label Oct 28, 2025
@codecov
Copy link

codecov bot commented Oct 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.09%. Comparing base (8dee1b5) to head (d4ba13b).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #983      +/-   ##
==========================================
+ Coverage   90.03%   90.09%   +0.06%     
==========================================
  Files          66       66              
  Lines       12344    12227     -117     
==========================================
- Hits        11114    11016      -98     
+ Misses       1230     1211      -19     

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

@j178 j178 marked this pull request as ready for review October 28, 2025 08:23
Copilot AI changed the title [WIP] Add support for excluding directories in .gitignored files Document that .gitignore is respected by default during workspace discovery Oct 28, 2025
Copilot AI requested a review from j178 October 28, 2025 08:24
@github-actions
Copy link

📦 Cargo Bloat Comparison

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

Expand for cargo-bloat output

PR Branch Results

 File  .text     Size          Crate Name
 0.6%   1.3% 101.1KiB          prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.5%   1.2%  88.0KiB           prek prek::languages::<impl prek::config::Language>::run::{{closure}}
 0.5%   1.1%  85.8KiB           prek prek::builtin::pre_commit_hooks::Implemented::run::{{closure}}
 0.4%   0.9%  63.8KiB           prek prek::archive::unpack::{{closure}}
 0.3%   0.7%  49.2KiB           prek prek::run::{{closure}}
 0.3%   0.6%  42.0KiB           prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.5%  40.9KiB regex_automata regex_automata::meta::strategy::new
 0.2%   0.5%  40.1KiB          prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.2%   0.4%  32.9KiB           prek prek::workspace::Workspace::discover
 0.2%   0.4%  32.8KiB           prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4%  32.3KiB           prek prek::languages::node::installer::NodeInstaller::install::{{closure}}
 0.2%   0.4%  31.8KiB             h2 h2::proto::connection::DynConnection<B>::recv_frame
 0.2%   0.4%  31.7KiB             h2 h2::proto::connection::Connection<T,P,B>::poll
 0.2%   0.4%  27.6KiB           prek prek::identify::by_extension::{{closure}}
 0.2%   0.3%  26.2KiB     hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.2%   0.3%  25.8KiB     hyper_util hyper_util::client::legacy::client::Client<C,B>::connect_to::{{closure}}::{{closure}}::{{closure}}
 0.2%   0.3%  25.0KiB        globset globset::GlobSetBuilder::build
 0.2%   0.3%  25.0KiB           prek prek::main
 0.1%   0.3%  24.2KiB           prek prek::languages::golang::installer::GoInstaller::install::{{closure}}
 0.1%   0.3%  23.7KiB          hyper hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_loop
39.8%  87.7%   6.4MiB                And 10186 smaller methods. Use -n N to show more.
45.4% 100.0%   7.3MiB                .text section size, the file size is 16.1MiB

Base Branch Results

 File  .text     Size          Crate Name
 0.6%   1.3% 101.1KiB          prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.5%   1.2%  88.0KiB           prek prek::languages::<impl prek::config::Language>::run::{{closure}}
 0.5%   1.1%  85.8KiB           prek prek::builtin::pre_commit_hooks::Implemented::run::{{closure}}
 0.4%   0.9%  63.8KiB           prek prek::archive::unpack::{{closure}}
 0.3%   0.7%  49.2KiB           prek prek::run::{{closure}}
 0.3%   0.6%  42.0KiB           prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.5%  40.9KiB regex_automata regex_automata::meta::strategy::new
 0.2%   0.5%  40.1KiB          prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.2%   0.4%  32.9KiB           prek prek::workspace::Workspace::discover
 0.2%   0.4%  32.8KiB           prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4%  32.3KiB           prek prek::languages::node::installer::NodeInstaller::install::{{closure}}
 0.2%   0.4%  31.8KiB             h2 h2::proto::connection::DynConnection<B>::recv_frame
 0.2%   0.4%  31.7KiB             h2 h2::proto::connection::Connection<T,P,B>::poll
 0.2%   0.4%  27.6KiB           prek prek::identify::by_extension::{{closure}}
 0.2%   0.3%  26.2KiB     hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.2%   0.3%  25.8KiB     hyper_util hyper_util::client::legacy::client::Client<C,B>::connect_to::{{closure}}::{{closure}}::{{closure}}
 0.2%   0.3%  25.0KiB        globset globset::GlobSetBuilder::build
 0.2%   0.3%  25.0KiB           prek prek::main
 0.1%   0.3%  24.2KiB           prek prek::languages::golang::installer::GoInstaller::install::{{closure}}
 0.1%   0.3%  23.7KiB          hyper hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_loop
39.8%  87.7%   6.4MiB                And 10186 smaller methods. Use -n N to show more.
45.4% 100.0%   7.3MiB                .text section size, the file size is 16.1MiB

@j178 j178 merged commit b524f38 into master Oct 28, 2025
21 checks passed
@j178 j178 deleted the copilot/add-prek-ignore-support branch October 28, 2025 08:31
feliblo pushed a commit to feliblo/prek that referenced this pull request Oct 29, 2025
…covery (j178#983)

* Initial plan

* Document that .gitignore is respected by default and add test

Co-authored-by: j178 <10510431+j178@users.noreply.github.com>

* Lint

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: j178 <10510431+j178@users.noreply.github.com>
feliblo pushed a commit to feliblo/prek that referenced this pull request Oct 29, 2025
…covery (j178#983)

* Initial plan

* Document that .gitignore is respected by default and add test

Co-authored-by: j178 <10510431+j178@users.noreply.github.com>

* Lint

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: j178 <10510431+j178@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't discover prek workspaces in .gitignored directories

2 participants