pre-commit/tests/languages
Sharmila Jesupaul 635912514d add pass_filenames_via_stdin for large changesets
pre-commit currently passes selected filenames to hooks via argv.
For large changesets (or --all-files), argv length limits are hit and
filenames are partitioned, causing multiple hook invocations.

This means there is currently no built-in way to pass filenames to an
underlying hook in one shot without chunking / re-running. The only practical
workaround is to set pass_filenames: false and run custom git operations in
hook code to reconstruct the file set, which is expensive and duplicates
pre-commit's own file-selection logic.

This change adds a hook option:

    pass_filenames_via_stdin: true

When enabled, pre-commit sends filenames as NUL-delimited bytes on stdin and
runs the hook in a single invocation (no argv chunking).

Why NUL-delimited stdin:
- safe for filenames containing spaces/newlines
- matches established -0 conventions in unix tooling

Usage for hook authors:
- shell:

    while IFS= read -r -d '' filename; do
        ...
    done

- python:

    data = sys.stdin.buffer.read()
    filenames = [os.fsdecode(p) for p in data.split(b'\0') if p]

Behavior notes:
- default remains argv-based passing
- pass_filenames: false still disables filename passing entirely

Implementation includes schema/runtime wiring, shared NUL encode/decode
helpers, and tests covering defaulting and runtime behavior.
2026-02-18 18:06:34 -08:00
..
__init__.py OMG we're running a hook 2014-03-13 22:12:33 -07:00
conda_test.py test conda language directly 2023-01-17 13:05:49 -05:00
coursier_test.py coursier: additional_dependencies support 2023-01-17 09:59:04 -05:00
dart_test.py Make Dart pre-commit hook compatible with the latest Dart SDKs 2025-08-08 17:14:59 +09:00
docker_image_test.py fix docker_image test when ubuntu:22.04 image is not pre-pulled 2024-12-28 15:45:05 -05:00
docker_test.py Fix docker-in-docker detection for cgroups v2 2025-11-08 15:37:32 -05:00
dotnet_test.py update .net tests to use .net 8 2024-12-28 15:50:58 -05:00
fail_test.py test fail language inline 2023-02-13 17:03:59 -06:00
golang_test.py disable automatic toolchain switching for golang hooks 2024-11-25 18:47:18 -05:00
haskell_test.py Add haskell language support to pre-commit. 2023-07-22 16:28:48 -04:00
julia_test.py Julia language: skip startup.jl file 2025-08-02 14:35:27 -04:00
lua_test.py test lua directly 2023-01-17 23:43:31 -05:00
node_test.py Bump Node.js version to 18.14.0 and Go to 1.21.1 2023-09-25 17:02:13 +08:00
perl_test.py test perl language directly 2023-01-17 17:34:04 -05:00
pygrep_test.py add pass_filenames_via_stdin for large changesets 2026-02-18 18:06:34 -08:00
python_test.py fix python local template when artifact dirs are present 2025-12-16 15:45:01 -05:00
r_test.py fix: ensure env patch is applied for vanilla emulation 2025-01-20 13:13:36 -05:00
ruby_test.py use a simpler gem for testing additional_dependencies 2024-04-29 21:28:16 -04:00
rust_test.py determine rust default language version independent of rust-toolchain.toml 2024-05-10 17:06:29 -04:00
swift_test.py test swift language directly 2023-01-17 13:51:06 -05:00
unsupported_script_test.py rename system and script languages to unsupported / unsupported_script 2025-11-08 15:09:16 -05:00
unsupported_test.py rename system and script languages to unsupported / unsupported_script 2025-11-08 15:09:16 -05:00