mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-07 21:44:18 +00:00
Fix #91 (bitbucket)
Non python files were being included in the git hook. Also, I realized that with --install-hook on git projects, the file was not readable to the user. Using binary helps clarify the use of chmod since I had erroneously used the 744 like the commandline does.
This commit is contained in:
parent
8935e0f5c1
commit
4efd19ce09
1 changed files with 7 additions and 2 deletions
|
|
@ -27,16 +27,20 @@ def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
|
||||||
"""
|
"""
|
||||||
gitcmd = "git diff-index --cached --name-only HEAD"
|
gitcmd = "git diff-index --cached --name-only HEAD"
|
||||||
if lazy:
|
if lazy:
|
||||||
|
# Catch all files, including those not added to the index
|
||||||
gitcmd = gitcmd.replace('--cached ', '')
|
gitcmd = gitcmd.replace('--cached ', '')
|
||||||
|
|
||||||
if hasattr(ignore, 'split'):
|
if hasattr(ignore, 'split'):
|
||||||
ignore = ignore.split(',')
|
ignore = ignore.split(',')
|
||||||
|
|
||||||
|
# Returns the exit code, list of files modified, list of error messages
|
||||||
_, files_modified, _ = run(gitcmd)
|
_, files_modified, _ = run(gitcmd)
|
||||||
|
|
||||||
|
# Run the checks
|
||||||
flake8_style = get_style_guide(
|
flake8_style = get_style_guide(
|
||||||
config_file=DEFAULT_CONFIG, ignore=ignore, max_complexity=complexity)
|
config_file=DEFAULT_CONFIG, ignore=ignore, max_complexity=complexity)
|
||||||
report = flake8_style.check_files(files_modified)
|
report = flake8_style.check_files([f for f in files_modified if
|
||||||
|
f.endswith('.py')])
|
||||||
|
|
||||||
if strict:
|
if strict:
|
||||||
return report.total_errors
|
return report.total_errors
|
||||||
|
|
@ -154,7 +158,8 @@ def install_hook():
|
||||||
if 'git' in vcs:
|
if 'git' in vcs:
|
||||||
with open(vcs, 'w+') as fd:
|
with open(vcs, 'w+') as fd:
|
||||||
fd.write(git_hook_file)
|
fd.write(git_hook_file)
|
||||||
os.chmod(vcs, 744)
|
# 0b111100100 == rwxr--r--
|
||||||
|
os.chmod(vcs, 0b111100100)
|
||||||
elif 'hg' in vcs:
|
elif 'hg' in vcs:
|
||||||
_install_hg_hook(vcs)
|
_install_hg_hook(vcs)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue