summaryrefslogtreecommitdiff
path: root/src/flake8
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2017-01-27 15:57:23 -0600
committerIan Cordasco <graffatcolmingov@gmail.com>2017-01-27 15:57:23 -0600
commit49fcbf468d1215c3a2a671c5c371679b8b6a246a (patch)
tree195a766d978a1b79a53f859cdd17d547e3082ef7 /src/flake8
parent77d887f4000fe3c85b6a191bff071d7c08d5e189 (diff)
downloadflake8-49fcbf468d1215c3a2a671c5c371679b8b6a246a.tar.gz
Do not run git-hook checks when there are no files
Apparently there are some cases where the git hook will not find files to run the checks against (e.g., when amending a commit message). In those cases, it's best not to attempt to run any checks and to allow the hook to exit successfully. Closes #303
Diffstat (limited to 'src/flake8')
-rw-r--r--src/flake8/main/git.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/flake8/main/git.py b/src/flake8/main/git.py
index 31404d8..57701f6 100644
--- a/src/flake8/main/git.py
+++ b/src/flake8/main/git.py
@@ -45,10 +45,17 @@ def hook(lazy=False, strict=False):
app.initialize(['.'])
app.options.exclude = update_excludes(app.options.exclude, tempdir)
app.options._running_from_vcs = True
- app.run_checks(filepaths)
+ # Apparently there are times when there are no files to check (e.g.,
+ # when amending a commit). In those cases, let's not try to run checks
+ # against nothing.
+ if filepaths:
+ app.run_checks(filepaths)
+
+ # If there were files to check, update their paths and report the errors
+ if filepaths:
+ update_paths(app.file_checker_manager, tempdir)
+ app.report_errors()
- update_paths(app.file_checker_manager, tempdir)
- app.report_errors()
if strict:
return app.result_count
return 0