Skip to content

Instantly share code, notes, and snippets.

@hughes
Last active December 21, 2015 11:25
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 hughes/aa511db78d534f9f1c53 to your computer and use it in GitHub Desktop.
Save hughes/aa511db78d534f9f1c53 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -n $VIRTUAL_ENV ]; then
PATH=$VIRTUAL_ENV/bin:$PATH
fi
REPO=$(pwd)
EXIT_CODE=0
for FILE in `git diff-index --name-only --cached HEAD -- | egrep .js$`; do
jshint ${REPO}/${FILE}
EXIT_CODE=$((${EXIT_CODE} + $?))
done
if [[ ${EXIT_CODE} -ne 0 ]]; then
echo "Aborted due to JSHint errors."
exit $EXIT_CODE
fi
for FILE in `git diff-index --name-only --cached HEAD -- | egrep .py$`; do
flake8 ${REPO}/${FILE} --max-complexity=10
EXIT_CODE=$((${EXIT_CODE} + $?))
done
if [[ ${EXIT_CODE} -ne 0 ]]; then
echo "Aborted due to flake8 errors."
exit $EXIT_CODE
fi
exit $EXIT_CODE
@brianpeiris
Copy link

To install this, copy it to a file called pre-commit under THM/.git/hooks/. Then chmod +x pre-commit.

@aehlke
Copy link

aehlke commented Apr 14, 2014

Fixed this in a fork: https://gist.github.com/aehlke/ea47c67a2cf1d01f711d so that this does not run flake8 on unstaged files, only on files that have been staged for the commit.

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