From f821f52ba363b911618f7a578c99741965087b92 Mon Sep 17 00:00:00 2001 From: Carl Mercier Date: Sun, 4 Dec 2016 11:00:11 -0600 Subject: [PATCH] Fail if grep cannot be executed --- pre_commit/languages/pcre.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pre_commit/languages/pcre.py b/pre_commit/languages/pcre.py index faba1da0..22f8114c 100644 --- a/pre_commit/languages/pcre.py +++ b/pre_commit/languages/pcre.py @@ -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'],)