pre-commit/tests/commands
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 Move commands into their own files. 2014-06-13 19:52:14 -07:00
autoupdate_test.py perform autoupdate without Store contention 2023-04-29 15:32:20 -04:00
clean_test.py drop python 3.6 support 2022-01-18 18:44:20 -05:00
gc_test.py move logic for gc back to commands.gc 2025-11-19 14:32:09 -05:00
hazmat_test.py add pre-commit hazmat 2025-11-22 13:53:53 -05:00
hook_impl_test.py Add pre-rebase hook support 2023-03-11 15:17:42 -05:00
init_templatedir_test.py Change cmd_output_bs retcode arg to a boolean check 2022-10-30 14:49:42 -05:00
install_uninstall_test.py python 3.9+: use removeprefix 2023-12-09 16:04:25 -05:00
migrate_config_test.py fix migrate-config for purelib yaml 2024-10-08 11:46:48 -04:00
run_test.py add pass_filenames_via_stdin for large changesets 2026-02-18 18:06:34 -08:00
sample_config_test.py drop python 3.6 support 2022-01-18 18:44:20 -05:00
try_repo_test.py Improve hook duration timing 2023-10-13 16:40:30 +01:00
validate_config_test.py remove pre-commit-validate-config and pre-commit-validate-manifest 2022-12-27 13:05:30 -05:00
validate_manifest_test.py remove pre-commit-validate-config and pre-commit-validate-manifest 2022-12-27 13:05:30 -05:00