diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..283b468 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,41 @@ +#!/bin/sh + +STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".py\{0,1\}$") + +if [[ "$STAGED_FILES" = "" ]]; then + exit 0 +fi + +PASS=true + +# Check for flake8 +which flake8 &> /dev/null +if [[ "$?" == 1 ]]; then + echo -e "\t\033[41mPlease install flake8\033[0m" + exit 1 +fi + +echo -e "\nLinting Python with Flake8:\n" + +for FILE in $STAGED_FILES +do + flake8 "$FILE" + + if [[ "$?" == 0 ]]; then + echo -e "\t\033[32mPassed: $FILE\033[0m" + else + echo -e "\t\033[41mFailed: $FILE\033[0m" + PASS=false + fi +done + +echo -e "\nPython linting complete!\n" + +if ! $PASS; then + echo -e "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again.\n" + exit 1 +else + echo -e "\033[42mCOMMIT SUCCEEDED\033[0m\n" +fi + +exit $? diff --git a/git-hook-install.sh b/git-hook-install.sh new file mode 100755 index 0000000..c94dbb3 --- /dev/null +++ b/git-hook-install.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +# Install pre-configured git hooks +git config --local core.hooksPath .githooks/