From 582c91701644b48d0f3970a8b2325dce2b3749d6 Mon Sep 17 00:00:00 2001 From: Zachary Barryte Date: Fri, 7 Sep 2018 14:22:28 -0400 Subject: [PATCH] Exclude folders from file list The previous implementation did not exclude folders, which could be included in the case of submodules --- pre_commit_hooks/detect_private_key.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pre_commit_hooks/detect_private_key.py b/pre_commit_hooks/detect_private_key.py index 693e59e..f1656be 100644 --- a/pre_commit_hooks/detect_private_key.py +++ b/pre_commit_hooks/detect_private_key.py @@ -1,6 +1,7 @@ from __future__ import print_function import argparse +import os import sys BLACKLIST = [ @@ -22,10 +23,11 @@ def detect_private_key(argv=None): private_key_files = [] for filename in args.filenames: - with open(filename, 'rb') as f: - content = f.read() - if any(line in content for line in BLACKLIST): - private_key_files.append(filename) + if os.path.isfile(filename): + with open(filename, 'rb') as f: + content = f.read() + if any(line in content for line in BLACKLIST): + private_key_files.append(filename) if private_key_files: for private_key_file in private_key_files: