mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 17:14:43 +04:00
use_filesnames_file
This commit is contained in:
parent
0252908c27
commit
47d0e05d09
5 changed files with 34 additions and 0 deletions
|
|
@ -128,6 +128,7 @@ MANIFEST_HOOK_DICT = cfgv.Map(
|
||||||
cfgv.Optional('always_run', cfgv.check_bool, False),
|
cfgv.Optional('always_run', cfgv.check_bool, False),
|
||||||
cfgv.Optional('fail_fast', cfgv.check_bool, False),
|
cfgv.Optional('fail_fast', cfgv.check_bool, False),
|
||||||
cfgv.Optional('pass_filenames', cfgv.check_bool, True),
|
cfgv.Optional('pass_filenames', cfgv.check_bool, True),
|
||||||
|
cfgv.Optional('use_filesnames_file', cfgv.check_bool, False),
|
||||||
cfgv.Optional('description', cfgv.check_string, ''),
|
cfgv.Optional('description', cfgv.check_string, ''),
|
||||||
cfgv.Optional('language_version', cfgv.check_string, C.DEFAULT),
|
cfgv.Optional('language_version', cfgv.check_string, C.DEFAULT),
|
||||||
cfgv.Optional('log_file', cfgv.check_string, ''),
|
cfgv.Optional('log_file', cfgv.check_string, ''),
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
|
|
@ -187,6 +188,11 @@ def _run_single_hook(
|
||||||
|
|
||||||
if not hook.pass_filenames:
|
if not hook.pass_filenames:
|
||||||
filenames = ()
|
filenames = ()
|
||||||
|
elif hook.use_filesnames_file:
|
||||||
|
filenames_file = tempfile.NamedTemporaryFile("w+")
|
||||||
|
filenames_file.write("\n".join(filenames))
|
||||||
|
filenames = (f"@{filenames_file}",)
|
||||||
|
|
||||||
time_before = time.monotonic()
|
time_before = time.monotonic()
|
||||||
language = languages[hook.language]
|
language = languages[hook.language]
|
||||||
with language.in_env(hook.prefix, hook.language_version):
|
with language.in_env(hook.prefix, hook.language_version):
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ class Hook(NamedTuple):
|
||||||
always_run: bool
|
always_run: bool
|
||||||
fail_fast: bool
|
fail_fast: bool
|
||||||
pass_filenames: bool
|
pass_filenames: bool
|
||||||
|
use_filesnames_file: bool
|
||||||
description: str
|
description: str
|
||||||
language_version: str
|
language_version: str
|
||||||
log_file: str
|
log_file: str
|
||||||
|
|
|
||||||
|
|
@ -1064,6 +1064,31 @@ def test_pass_filenames(
|
||||||
assert (b'foo.py' in printed) == pass_filenames
|
assert (b'foo.py' in printed) == pass_filenames
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
('use_filesnames_file', 'hook_args'),
|
||||||
|
(
|
||||||
|
(True, []),
|
||||||
|
(False, []),
|
||||||
|
(True, ['some', 'args']),
|
||||||
|
(False, ['some', 'args']),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_use_filesnames_file(
|
||||||
|
cap_out, store, repo_with_passing_hook,
|
||||||
|
use_filesnames_file, hook_args,
|
||||||
|
):
|
||||||
|
with modify_config() as config:
|
||||||
|
config['repos'][0]['hooks'][0]['use_filesnames_file'] = use_filesnames_file
|
||||||
|
config['repos'][0]['hooks'][0]['args'] = hook_args
|
||||||
|
stage_a_file()
|
||||||
|
ret, printed = _do_run(
|
||||||
|
cap_out, store, repo_with_passing_hook, run_opts(verbose=True),
|
||||||
|
)
|
||||||
|
out_lines = printed.splitlines()
|
||||||
|
out_lines[-1] == b"Hello World"
|
||||||
|
assert out_lines[-2].startswith(b"@") == use_filesnames_file
|
||||||
|
|
||||||
|
|
||||||
def test_fail_fast(cap_out, store, repo_with_failing_hook):
|
def test_fail_fast(cap_out, store, repo_with_failing_hook):
|
||||||
with modify_config() as config:
|
with modify_config() as config:
|
||||||
# More than one hook
|
# More than one hook
|
||||||
|
|
|
||||||
|
|
@ -455,6 +455,7 @@ def test_manifest_hooks(tempdir_factory, store):
|
||||||
minimum_pre_commit_version='0',
|
minimum_pre_commit_version='0',
|
||||||
name='Bash hook',
|
name='Bash hook',
|
||||||
pass_filenames=True,
|
pass_filenames=True,
|
||||||
|
use_filesnames_file=False,
|
||||||
require_serial=False,
|
require_serial=False,
|
||||||
stages=[
|
stages=[
|
||||||
'commit-msg',
|
'commit-msg',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue