Last active
January 5, 2021 07:08
-
-
Save mehulved/94f8cab98b33d5f156c0d3e73f6a23b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Check and stop unallowed file names from being checked in | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
# Initial commit: diff against an empty tree object | |
against=$(git hash-object -t tree /dev/null) | |
fi | |
# Redirect output to stderr. | |
exec 1>&2 | |
# Lint all the python files that have been added, changed, moved or renamed. | |
CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR) | |
for FILE in $CHANGED_FILES | |
do | |
if [[ ${FILE##*.} == "py" ]] | |
then | |
pylint -r n -s n $FILE | |
EXIT_CODE=$? | |
echo $EXIT_CODE | |
if [ ! -z "$EXIT_CODE" ] | |
then | |
echo "Linting errors found in file $FILE. Exiting..." | |
exit $EXIT_CODE | |
fi | |
fi | |
done | |
# Run tests | |
pytest --cov=classes --cov-config=coverage.ini tests/*/* | |
# If there are whitespace errors, print the offending file names and fail. | |
exec git diff-index --check --cached $against -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment