mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Add pass_filenames hook option
This option controls whether filenames are passed along as arguments to the hook program.
This commit is contained in:
parent
6025475afb
commit
e774c09fac
4 changed files with 33 additions and 1 deletions
|
|
@ -731,3 +731,29 @@ def test_files_running_subdir(
|
|||
tempdir_factory=tempdir_factory,
|
||||
)
|
||||
assert 'subdir/foo.py'.replace('/', os.sep) in stdout
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('pass_filenames', 'hook_args', 'expected_out'),
|
||||
(
|
||||
(True, [], b'foo.py'),
|
||||
(False, [], b''),
|
||||
(True, ['some', 'args'], b'some args foo.py'),
|
||||
(False, ['some', 'args'], b'some args'),
|
||||
)
|
||||
)
|
||||
def test_pass_filenames(
|
||||
cap_out, repo_with_passing_hook, mock_out_store_directory,
|
||||
pass_filenames,
|
||||
hook_args,
|
||||
expected_out,
|
||||
):
|
||||
with modify_config() as config:
|
||||
config[0]['hooks'][0]['pass_filenames'] = pass_filenames
|
||||
config[0]['hooks'][0]['args'] = hook_args
|
||||
stage_a_file()
|
||||
ret, printed = _do_run(
|
||||
cap_out, repo_with_passing_hook, _get_opts(verbose=True),
|
||||
)
|
||||
assert expected_out + b'\nHello World' in printed
|
||||
assert ('foo.py' in printed) == pass_filenames
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ def test_manifest_contents(manifest):
|
|||
'log_file': '',
|
||||
'minimum_pre_commit_version': '0',
|
||||
'name': 'Bash hook',
|
||||
'pass_filenames': True,
|
||||
'stages': [],
|
||||
}]
|
||||
|
||||
|
|
@ -51,6 +52,7 @@ def test_hooks(manifest):
|
|||
'log_file': '',
|
||||
'minimum_pre_commit_version': '0',
|
||||
'name': 'Bash hook',
|
||||
'pass_filenames': True,
|
||||
'stages': [],
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue