Skip to content

Instantly share code, notes, and snippets.

@atelic
Created August 3, 2016 21:05
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 atelic/86dac06e0d77de8197fe24a002385dd3 to your computer and use it in GitHub Desktop.
Save atelic/86dac06e0d77de8197fe24a002385dd3 to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
RUN_TEST_COMMAND=""
find . -name "*.pyc" -delete
git diff --cached --name-only | while read FILE; do
if [[ "$FILE" =~ ^.+(py)$ ]]; then
if [[ -f $FILE ]]; then
python -m py_compile "$FILE" 1> /dev/null
if [ $? -ne 0 ]; then
echo -e "\e[1;31mAborting commit due to files with syntax errors.\e[0m" >&2
exit 1
fi
RESULT=$(grep "ipdb.set" "$FILE")
if [ ! -z $RESULT ]; then
echo -e "\e[1;33mWarning, the commit contains a call to ipdb. Commit was not aborted, however.\e[0m" >&2
fi
fi
elif [[ "$FILE" =~ ^.+(js|jsx|html)$ ]]; then
if [[ -f "$FILE" ]]; then
RESULT=$(grep "debugger" "$FILE")
if [ ! -z $RESULT ]; then
echo -e "\e[1;33mAborting commit due to call to debuger;.\e[0m" >&2
exit 1
fi
fi
fi
done || exit $?
if [ $? -eq 0 ]; then
"$RUN_TEST_COMMAND"
if [ $? -ne 0 ]; then
echo -e "\e[1;31m\tUnit tests failed ! Aborting commit.\e[0m" >&2
exit 1;
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment