Fail if grep cannot be executed

This commit is contained in:
Carl Mercier 2016-12-04 11:00:11 -06:00
parent 0e2c3c1ff9
commit f821f52ba3

View file

@ -4,6 +4,7 @@ from sys import platform
from pre_commit.xargs import xargs
import os
ENVIRONMENT_DIR = None
@ -18,9 +19,15 @@ def install_environment(
def run_hook(repo_cmd_runner, hook, file_args):
grep_command = 'ggrep' if platform == 'darwin' else 'grep'
# Determine if grep is installed on system
if os.system('which ' + grep_command) != 0:
raise AssertionError('Cannot execute grep command: ' + grep_command)
# For PCRE the entry is the regular expression to match
cmd = (
'ggrep' if platform == 'darwin' else 'grep',
grep_command,
'-H', '-n', '-P',
) + tuple(hook['args']) + (hook['entry'],)