Skip to content

fix: use split() instead of resolve(None) for builtin hook argument parsing#1415

Merged
j178 merged 2 commits intoj178:masterfrom
shaanmajid:fix/1412-builtin-hooks-resolve
Jan 19, 2026
Merged

fix: use split() instead of resolve(None) for builtin hook argument parsing#1415
j178 merged 2 commits intoj178:masterfrom
shaanmajid:fix/1412-builtin-hooks-resolve

Conversation

@shaanmajid
Copy link
Collaborator

@shaanmajid shaanmajid commented Jan 19, 2026

Builtin hooks were using resolve(None) to parse entry arguments, which searches PATH and parses shebangs. When pre-commit-hooks is pip-installed, binaries like trailing-whitespace-fixer exist on PATH with shebangs—this corrupted argument parsing.

The fix uses split() instead, which just parses the entry string into arguments without PATH resolution. Builtin hooks don't execute external binaries, so this is the correct approach.

Test plan

# Build prek from this PR
cargo build --release

# Set up test repo with pre-commit-hooks on PATH
cd /tmp && rm -rf prek-test && mkdir prek-test && cd prek-test
git init && uv venv && uv pip install pre-commit-hooks

cat > .pre-commit-config.yaml << 'YAML'
repos:
  - repo: builtin
    hooks:
      - id: trailing-whitespace
YAML

echo "hello   " > test.txt && git add .

# Run with venv bin on PATH - should succeed (exit 1 = hook fixed file)
PATH="$PWD/.venv/bin:$PATH" /path/to/prek/target/release/prek run

Fixes #1412

@shaanmajid shaanmajid force-pushed the fix/1412-builtin-hooks-resolve branch 2 times, most recently from 4222aed to 1e6806a Compare January 19, 2026 20:01
@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1415   +/-   ##
=======================================
  Coverage   90.66%   90.66%           
=======================================
  Files          82       82           
  Lines       16698    16698           
=======================================
  Hits        15140    15140           
  Misses       1558     1558           

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

@github-actions
Copy link

github-actions bot commented Jan 19, 2026

📦 Cargo Bloat Comparison

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

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size        Crate Name
 0.3%   0.8% 71.4KiB        prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 62.5KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.6% 55.3KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 46.3KiB         prek prek::run::{{closure}}
 0.2%   0.5% 42.7KiB         prek prek::cli::run::run::run::{{closure}}
 0.2%   0.5% 42.7KiB         prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 35.1KiB         prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.1%   0.3% 31.8KiB        prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 30.0KiB  serde_json? <&mut serde_json::de::Deserializer<R> as serde_core::de::Deserializer>::deserialize_struct
 0.1%   0.2% 21.5KiB         prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 21.3KiB clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 19.6KiB         prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.3KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.9KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.6KiB         ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.3KiB         prek prek::hooks::meta_hooks::check_hooks_apply::{{closure}}
 0.1%   0.2% 18.3KiB         prek prek::hooks::meta_hooks::check_hooks_apply::{{closure}}
 0.1%   0.2% 18.2KiB   hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.2% 18.1KiB    [Unknown] fe_loose_invert
 0.1%   0.2% 17.7KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
36.6%  91.6%  8.2MiB              And 19831 smaller methods. Use -n N to show more.
40.0% 100.0%  9.0MiB              .text section size, the file size is 22.5MiB

Base Branch Results

 File  .text    Size        Crate Name
 0.3%   0.8% 71.4KiB        prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 62.6KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.6% 55.3KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 46.3KiB         prek prek::run::{{closure}}
 0.2%   0.5% 42.7KiB         prek prek::cli::run::run::run::{{closure}}
 0.2%   0.5% 42.7KiB         prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 35.1KiB         prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.1%   0.3% 31.8KiB        prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 30.0KiB  serde_json? <&mut serde_json::de::Deserializer<R> as serde_core::de::Deserializer>::deserialize_struct
 0.1%   0.2% 21.5KiB         prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 21.3KiB clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 19.6KiB         prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.3KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.9KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.6KiB         ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.3KiB         prek prek::hooks::meta_hooks::check_hooks_apply::{{closure}}
 0.1%   0.2% 18.3KiB         prek prek::hooks::meta_hooks::check_hooks_apply::{{closure}}
 0.1%   0.2% 18.2KiB   hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.2% 18.1KiB    [Unknown] fe_loose_invert
 0.1%   0.2% 17.7KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
36.6%  91.6%  8.2MiB              And 19832 smaller methods. Use -n N to show more.
40.0% 100.0%  9.0MiB              .text section size, the file size is 22.5MiB

@shaanmajid shaanmajid force-pushed the fix/1412-builtin-hooks-resolve branch from 1e6806a to a7622ed Compare January 19, 2026 20:35
…arsing

Builtin hooks were calling `hook.entry.resolve(None)` to get arguments
for clap parsing. After commit 85448ac, `resolve(None)` falls back to
system PATH, which can find system-wide binaries (e.g., from
`pip install pre-commit-hooks`), parse their shebangs, and corrupt
argument parsing.

The fix changes these 6 builtin hooks to use `split()` instead, which
just tokenizes the entry string without PATH resolution - exactly what's
needed for argument parsing.

Fixes j178#1412
@shaanmajid shaanmajid force-pushed the fix/1412-builtin-hooks-resolve branch 2 times, most recently from a6a56f3 to e2484e1 Compare January 19, 2026 21:06
@j178 j178 added the bug Something isn't working label Jan 19, 2026
@shaanmajid shaanmajid force-pushed the fix/1412-builtin-hooks-resolve branch 2 times, most recently from 192ed89 to 0e1a1ce Compare January 19, 2026 21:18
Adds a test that verifies builtin hooks work correctly even when
system-wide binaries with matching names exist on PATH (e.g., from
`pip install pre-commit-hooks`).

The test creates a fake `trailing-whitespace-fixer` binary with a
shebang in a temp directory, adds it to PATH, and verifies the builtin
trailing-whitespace hook still works correctly.
@shaanmajid shaanmajid force-pushed the fix/1412-builtin-hooks-resolve branch from 0e1a1ce to d5b7373 Compare January 19, 2026 21:19
@j178 j178 merged commit dcf2c5a into j178:master Jan 19, 2026
22 checks passed
@j178
Copy link
Owner

j178 commented Jan 19, 2026

Thanks!

@j178 j178 mentioned this pull request Jan 22, 2026
@shaanmajid shaanmajid deleted the fix/1412-builtin-hooks-resolve branch January 22, 2026 06:47
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.

unexpected argument '/usr/local/bin/trailing-whitespace-fixer' found on 0.2.30

2 participants