Simplify linting git hook script
This commit is contained in:
parent
42a74c2bc9
commit
7cec1425b3
|
@ -1,12 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".py\{0,1\}$")
|
||||
docker run --rm -v "$PWD:$PWD:z" -w "$PWD" python:3.9-bullseye sh -c './lint-docker.sh'
|
||||
|
||||
if [[ "$STAGED_FILES" = "" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
docker run --rm -v "$PWD:$PWD:z" -w "$PWD" -e "STAGED_FILES=$STAGED_FILES" python:3.7-buster sh -c './lint-docker.sh "$STAGED_FILES"'
|
||||
RUN_STATUS=$?
|
||||
|
||||
exit $RUN_STATUS
|
||||
exit $?
|
||||
|
|
|
@ -2,30 +2,17 @@
|
|||
|
||||
. venv/bin/activate
|
||||
|
||||
STAGED_FILES="$1"
|
||||
|
||||
echo "STAGED_FILES: $STAGED_FILES"
|
||||
|
||||
echo -e "\nLinting Python files with Flake8:\n"
|
||||
|
||||
PASS=true
|
||||
|
||||
while IFS= read -r FILE; do
|
||||
flake8 "$FILE"
|
||||
|
||||
if [[ "$?" != 0 ]]; then
|
||||
PASS=false
|
||||
fi
|
||||
# echo "Linted $FILE"
|
||||
done <<< "$STAGED_FILES"
|
||||
flake8
|
||||
PASS=$?
|
||||
|
||||
echo -e "\nPython linting complete!\n"
|
||||
|
||||
if ! $PASS; then
|
||||
if [ "$PASS" -eq 0 ]; then
|
||||
echo -e "\033[42mCOMMIT SUCCEEDED\033[0m\n"
|
||||
exit $?
|
||||
else
|
||||
echo -e "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass flake8 but do not. Please fix the flake8 errors and try again.\n"
|
||||
exit 1
|
||||
else
|
||||
echo -e "\033[42mCOMMIT SUCCEEDED\033[0m\n"
|
||||
fi
|
||||
|
||||
exit $?
|
||||
|
|
Loading…
Reference in New Issue