Skip to content

Instantly share code, notes, and snippets.

@curtischong curtischong/pre-commit
Last active Jun 19, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.