pre-commit/tests
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
..
commands add pass_filenames_via_stdin for large changesets 2026-02-18 18:06:34 -08:00
languages add pass_filenames_via_stdin for large changesets 2026-02-18 18:06:34 -08:00
meta_hooks drop python 3.6 support 2022-01-18 18:44:20 -05:00
__init__.py Initial commit. 2014-03-12 20:25:19 -07:00
clientlib_test.py add pass_filenames_via_stdin for large changesets 2026-02-18 18:06:34 -08:00
color_test.py drop python 3.6 support 2022-01-18 18:44:20 -05:00
conftest.py replace log_info_mock with pytest's caplog 2024-09-30 19:58:16 -04:00
envcontext_test.py drop python 3.6 support 2022-01-18 18:44:20 -05:00
error_handler_test.py Remove expected_returncode from CalledProcessError 2022-10-30 15:31:45 -05:00
git_test.py fix: crash on ambiguous ref 'HEAD' 2025-03-15 15:23:15 -04:00
lang_base_test.py add pass_filenames_via_stdin for large changesets 2026-02-18 18:06:34 -08:00
logging_handler_test.py drop python 3.6 support 2022-01-18 18:44:20 -05:00
main_test.py Merge pull request #3585 from pre-commit/hazmat 2025-11-22 14:03:09 -05:00
output_test.py drop python 3.6 support 2022-01-18 18:44:20 -05:00
parse_shebang_test.py use sys.executable instead of echo.exe in parse_shebang 2023-10-09 16:49:30 -04:00
prefix_test.py drop python 3.6 support 2022-01-18 18:44:20 -05:00
repository_test.py add pass_filenames_via_stdin for large changesets 2026-02-18 18:06:34 -08:00
staged_files_only_test.py staged_files_only can handle a crlf-only diff 2024-02-10 14:01:49 -05:00
store_test.py move logic for gc back to commands.gc 2025-11-19 14:32:09 -05:00
util_test.py fix trailing whitespace in CalledProcessError output 2023-02-21 12:42:09 -05:00
xargs_test.py Refactor target_concurrency tests 2023-09-10 08:39:19 -04:00
yaml_rewrite_test.py change migrate-config to use yaml parse tree instead 2024-09-16 20:16:16 -04:00