Skip to content

Commit f0c198f

Browse files
committed
Allow args for pcre hook
1 parent 8a43a65 commit f0c198f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

pre_commit/languages/pcre.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ def run_hook(repo_cmd_runner, hook, file_args):
2525
'xargs', '-0', 'sh', '-c',
2626
# Grep usually returns 0 for matches, and nonzero for non-matches
2727
# so we flip it here.
28-
'! {0} {1} $@'.format(grep_command, shell_escape(hook['entry'])),
28+
'! {0} {1} {2} $@'.format(
29+
grep_command, ' '.join(hook['args']),
30+
shell_escape(hook['entry'])),
2931
'--',
3032
],
3133
stdin=file_args_to_stdin(file_args),

testing/resources/pcre_hooks_repo/hooks.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@
88
entry: ^\[INFO\]
99
language: pcre
1010
files: ''
11+
- id: regex-with-grep-args
12+
name: Regex with grep extra arguments
13+
entry: foo\sbar
14+
language: pcre
15+
files: ''
16+
args: [-z]

tests/repository_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,21 @@ def test_pcre_hook_matching(tempdir_factory, store):
222222
)
223223

224224

225+
@xfailif_no_pcre_support
226+
@pytest.mark.integration
227+
def test_pcre_hook_extra_multiline_option(tempdir_factory, store):
228+
path = git_dir(tempdir_factory)
229+
with cwd(path):
230+
with io.open('herp', 'w') as herp:
231+
herp.write("foo\nbar\n")
232+
233+
_test_hook_repo(
234+
tempdir_factory, store, 'pcre_hooks_repo',
235+
'regex-with-grep-args', ['herp'], b"herp:1:foo\nbar\n\x00",
236+
expected_return_code=123,
237+
)
238+
239+
225240
@xfailif_no_pcre_support
226241
@pytest.mark.integration
227242
def test_pcre_many_files(tempdir_factory, store):

0 commit comments

Comments
 (0)