From bfd7092effaf344d13e7365eeaf994101df3a32a Mon Sep 17 00:00:00 2001 From: Curzy Date: Sun, 5 Feb 2017 03:17:49 +0900 Subject: [PATCH] Git pre-commit hook should not check non-python, excluded files This commit fixes two problems that caused by git pre-commit hook 1. flake8 checks non-python files(.md, .txt, ...) and raise errors ```/var/folders/bb/0_8jdgw15f72f18m_fpqwcqr0000gn/T/tmpqbcrt3vn/Users/Curzy/Workspace/flative/hbnn/hbnn/README.md:3:2: E999 SyntaxError: invalid syntax /var/folders/bb/0_8jdgw15f72f18m_fpqwcqr0000gn/T/tmpqbcrt3vn/Users/Curzy/Workspace/flative/hbnn/hbnn/README.md:3:20: E226 missing whitespace around arithmetic operator``` this problem fixed with find_modified_files function 2. flake8 checks excluded files by config(.flake8, config, ...) ```.flake8 [flake8] ignore = F401 exclude = .git, __pycache__, hbnn/settings.py, manage.py, */migrations ``` ``` ./hbnn/settings.py:102:80: E501 line too long (83 > 79 characters) ./user/migrations/0001_initial.py:20:80: E501 line too long (88 > 79 characters) ./user/migrations/0001_initial.py:21:80: E501 line too long (103 > 79 characters) ``` this problem fixed with update_execuldes function should contain both original, temp paths --- src/flake8/main/git.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/flake8/main/git.py b/src/flake8/main/git.py index 57701f6..85accc7 100644 --- a/src/flake8/main/git.py +++ b/src/flake8/main/git.py @@ -153,7 +153,7 @@ def make_temporary_directory_from(destination, directory): def find_modified_files(lazy): diff_index_cmd = [ 'git', 'diff-index', '--cached', '--name-only', - '--diff-filter=ACMRTUXB', 'HEAD' + '--diff-filter=ACMRTUXB', 'HEAD', '|', 'grep', '-e', '\.py$' ] if lazy: diff_index_cmd.remove('--cached') @@ -206,10 +206,10 @@ def config_for(parameter): def update_excludes(exclude_list, temporary_directory_path): - return [ + return exclude_list + [ (temporary_directory_path + pattern) - if os.path.isabs(pattern) else pattern for pattern in exclude_list + if os.path.isabs(pattern) ]