Skip to content

Instantly share code, notes, and snippets.

@atarkowska
Created September 14, 2016 09:15
Show Gist options
  • Save atarkowska/c51f94f5aa9c6d4463a490cecd524ef8 to your computer and use it in GitHub Desktop.
Save atarkowska/c51f94f5aa9c6d4463a490cecd524ef8 to your computer and use it in GitHub Desktop.
pre-commit hooks
#!/bin/sh
# automatically configured by git-annex
FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -e '\.py$')
if [ -n "$FILES" ]; then
if output=$(flake8 $FILES) && [ -z "$output" ]; then
echo 'Flake8 pass. Ready to commit.'
else
echo 'Flake8 errors.'
echo "$output"
exit 1
fi
fi
if [ -n "$FILES" ]; then
if output=$(pylint --disable all --enable spelling --spelling-dict en_US $FILES) && [ -z "$output" ]; then
echo 'Spelling ok'
else
echo 'Spelling errors.'
echo "$output"
# Allows us to read user input below, assigns stdin to keyboard
exec < /dev/tty
while true; do
read -p "Would you like to commit? (Y/n) " yn
if [ "$yn" = "" ]; then
yn='Y'
fi
case $yn in
[Yy] ) bundle outdated --pre; break;;
[Nn] ) exit 1;;
* ) echo "Please answer y or n for yes or no.";;
esac
done
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment