mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 00:54:42 +04:00
Use ggrep instead of grep for pcre on mac os
This commit is contained in:
parent
3d90b094fc
commit
7fd709ebd3
1 changed files with 7 additions and 1 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from sys import platform
|
||||||
|
|
||||||
from pre_commit.languages.helpers import file_args_to_stdin
|
from pre_commit.languages.helpers import file_args_to_stdin
|
||||||
from pre_commit.util import shell_escape
|
from pre_commit.util import shell_escape
|
||||||
|
|
||||||
|
|
@ -13,13 +15,17 @@ def install_environment(repo_cmd_runner, version='default'):
|
||||||
|
|
||||||
|
|
||||||
def run_hook(repo_cmd_runner, hook, file_args):
|
def run_hook(repo_cmd_runner, hook, file_args):
|
||||||
|
grep_command = 'grep -H -n -P'
|
||||||
|
if platform == 'darwin':
|
||||||
|
grep_command = 'ggrep -H -n -P'
|
||||||
|
|
||||||
# For PCRE the entry is the regular expression to match
|
# For PCRE the entry is the regular expression to match
|
||||||
return repo_cmd_runner.run(
|
return repo_cmd_runner.run(
|
||||||
[
|
[
|
||||||
'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.
|
||||||
'! grep -H -n -P {0} $@'.format(shell_escape(hook['entry'])),
|
'! {0} {1} $@'.format(grep_command, shell_escape(hook['entry'])),
|
||||||
'--',
|
'--',
|
||||||
],
|
],
|
||||||
stdin=file_args_to_stdin(file_args),
|
stdin=file_args_to_stdin(file_args),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue