Skip to content

Instantly share code, notes, and snippets.

@curtischong
Last active June 19, 2019 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curtischong/6f21c7d36391fe51be9443f2b8fc0ffd to your computer and use it in GitHub Desktop.
Save curtischong/6f21c7d36391fe51be9443f2b8fc0ffd to your computer and use it in GitHub Desktop.
git pre-commit flake8 cancer
#!/bin/bash
# TODO: Place in .git/hooks/
# TODO: Run chmod +x pre-commit
changed-files () {
git diff-tree --no-commit-id --name-only -r ${@:-HEAD}
}
exists () {
while read line; do
test -f $line && echo $line
done
}
root=$(git rev-parse --show-toplevel)
cd $root
# To check the flake8 for the file's imports use: --builtins=func_name
files=$(changed-files $@ | grep '\.py$' | exists)
test -z "$files" || flake8 --ignore=W292,E501,E265,F404,E302,E305 $files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment