Add black formatting hook

This commit is contained in:
Sonny 2019-08-24 19:20:18 +02:00
parent a08e8e9a74
commit c41085a264

16
pre-commit.d/black.sh Normal file
View file

@ -0,0 +1,16 @@
#!/bin/bash
FILES=$(git diff --cached --name-only --diff-filter=ACM "*.py" | sed 's| |\\ |g')
LINE_LENGTH=90
if [ ! -z "$FILES" ]; then
# Format all selected files
echo "$FILES" | xargs $HOME/.local/bin/black -l $LINE_LENGTH
if [ $? -ne 0 ]; then
exit 1
fi
# Add back the modified files to staging
echo "$FILES" | xargs git add
fi