mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #292 from pricematch/pcre_args
Allow args for pcre hook
This commit is contained in:
commit
8ccd2816d1
3 changed files with 24 additions and 1 deletions
|
|
@ -25,7 +25,9 @@ def run_hook(repo_cmd_runner, hook, file_args):
|
||||||
'xargs', '-0', 'sh', '-c',
|
'xargs', '-0', 'sh', '-c',
|
||||||
# Grep usually returns 0 for matches, and nonzero for non-matches
|
# Grep usually returns 0 for matches, and nonzero for non-matches
|
||||||
# so we flip it here.
|
# so we flip it here.
|
||||||
'! {0} {1} $@'.format(grep_command, shell_escape(hook['entry'])),
|
'! {0} {1} {2} $@'.format(
|
||||||
|
grep_command, ' '.join(hook['args']),
|
||||||
|
shell_escape(hook['entry'])),
|
||||||
'--',
|
'--',
|
||||||
],
|
],
|
||||||
stdin=file_args_to_stdin(file_args),
|
stdin=file_args_to_stdin(file_args),
|
||||||
|
|
|
||||||
|
|
@ -8,3 +8,9 @@
|
||||||
entry: ^\[INFO\]
|
entry: ^\[INFO\]
|
||||||
language: pcre
|
language: pcre
|
||||||
files: ''
|
files: ''
|
||||||
|
- id: regex-with-grep-args
|
||||||
|
name: Regex with grep extra arguments
|
||||||
|
entry: foo\sbar
|
||||||
|
language: pcre
|
||||||
|
files: ''
|
||||||
|
args: [-z]
|
||||||
|
|
|
||||||
|
|
@ -222,6 +222,21 @@ def test_pcre_hook_matching(tempdir_factory, store):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@xfailif_no_pcre_support
|
||||||
|
@pytest.mark.integration
|
||||||
|
def test_pcre_hook_extra_multiline_option(tempdir_factory, store):
|
||||||
|
path = git_dir(tempdir_factory)
|
||||||
|
with cwd(path):
|
||||||
|
with io.open('herp', 'w') as herp:
|
||||||
|
herp.write("foo\nbar\n")
|
||||||
|
|
||||||
|
_test_hook_repo(
|
||||||
|
tempdir_factory, store, 'pcre_hooks_repo',
|
||||||
|
'regex-with-grep-args', ['herp'], b"herp:1:foo\nbar\n\x00",
|
||||||
|
expected_return_code=123,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@xfailif_no_pcre_support
|
@xfailif_no_pcre_support
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_pcre_many_files(tempdir_factory, store):
|
def test_pcre_many_files(tempdir_factory, store):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue