| 1 |
# this is an example how to use git pre-commit hooks on windows to make sure code format is correct. |
| 2 |
# Place in .git\hooks and remove the first two lines. (Assuming you have git installed in default path.) |
| 3 |
#!C:/Program\ Files/Git/bin/sh.exe |
| 4 |
for file in $(git diff --cached --name-only | grep -E '\.(py)$') |
| 5 |
do |
| 6 |
if [ -f "$file" ]; then |
| 7 |
echo "Reformat '$file'" |
| 8 |
black -l 120 "$file" |
| 9 |
isort -l 120 -l 120 --lbt 1 "$file" |
| 10 |
git add "$file" |
| 11 |
|
| 12 |
flake8 --max-line-length=120 --ignore=F401,W503,E203 "$file" |
| 13 |
if [ $? -ne 0 ]; then |
| 14 |
echo "flake8 failed on staged file '$file'" |
| 15 |
exit 1 # exit with failure status |
| 16 |
fi |
| 17 |
fi |
| 18 |
done |