Skip to content

Instantly share code, notes, and snippets.

@awestendorf
Last active May 17, 2018 16:01
Show Gist options
  • Save awestendorf/47c169bc48ade77cb5e6 to your computer and use it in GitHub Desktop.
Save awestendorf/47c169bc48ade77cb5e6 to your computer and use it in GitHub Desktop.
Run flake8 on the set of changes in a pre-commit hook
#!/bin/bash
# Place in .git/hooks/pre-commit
# Filters out deleted files with --diff-filter
# GNU
git diff --cached --name-only --diff-filter=ACMRTUXB | grep .py | xargs --no-run-if-empty flake8 $FLAKE
# BSD
git diff --cached --name-only --diff-filter=ACMRTUXB | (grep .py || echo " ") | xargs flake8 $FLAKE
@awestendorf
Copy link
Author

To ignore all errors when committing:

FLAKE="--exit-zero" git commit <files>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment