From 28f0d160730e6fa3ef1f4b4ce768e61a8d662047 Mon Sep 17 00:00:00 2001 From: Edgar Geier Date: Tue, 23 Jul 2019 00:40:51 +0200 Subject: [PATCH] Catch CalledProcessError when running outside a git repository --- pre_commit/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pre_commit/main.py b/pre_commit/main.py index 770abf3a..d6c65970 100644 --- a/pre_commit/main.py +++ b/pre_commit/main.py @@ -42,7 +42,11 @@ def _file_path(path): elif os.path.exists(path): msg = '{} is not a regular file'.format(path) raise argparse.ArgumentTypeError(msg) - git_path = os.path.join(git.get_root(), path) + try: + git_path = os.path.join(git.get_root(), path) + except CalledProcessError: + msg = '{} does not exist'.format(path) + raise argparse.ArgumentTypeError(msg) if os.path.isfile(git_path): return git_path else: