Add --hook-args option to try-repo

This commit is contained in:
George Ogden 2025-10-06 18:19:04 +02:00
parent 99fa9ba5ef
commit 6d22fc01d0
No known key found for this signature in database
GPG key ID: 7535155E9AA29EDB
3 changed files with 53 additions and 3 deletions

View file

@ -19,8 +19,13 @@ from testing.util import git_commit
from testing.util import run_opts
def try_repo_opts(repo, ref=None, **kwargs):
return auto_namedtuple(repo=repo, ref=ref, **run_opts(**kwargs)._asdict())
def try_repo_opts(repo, ref=None, hook_args=None, **kwargs):
return auto_namedtuple(
repo=repo,
ref=ref,
hook_args=hook_args,
**run_opts(**kwargs)._asdict(),
)
def _get_out(cap_out):
@ -89,6 +94,33 @@ Bash hook............................................(no files to check)Skipped
'''
def test_try_repo_with_specific_hook_and_args(cap_out, tempdir_factory):
_run_try_repo(
tempdir_factory,
hook='bash_hook',
hook_args=['pwd', '&&', 'ls'],
verbose=True,
)
start, config, rest = _get_out(cap_out)
assert start == ''
config_pattern = re_assert.Matches(
'^repos:\n'
'- repo: .+\n'
' rev: .+\n'
' hooks:\n'
' - id: bash_hook\n'
' args:\n'
' - pwd\n'
' - \'&&\'\n'
' - ls\n$',
)
config_pattern.assert_matches(config)
assert rest == '''\
Bash hook............................................(no files to check)Skipped
- hook id: bash_hook
'''
def test_try_repo_relative_path(cap_out, tempdir_factory):
repo = make_repo(tempdir_factory, 'modified_file_returns_zero_repo')
with cwd(git_dir(tempdir_factory)):