Use more robust pre-commit.
parent
b4e42e6de2
commit
9a5274f0dd
|
@ -1,12 +1,21 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
FORMAT_FILES=$(
|
STAGED=$(
|
||||||
git --no-pager diff --name-status --no-color --cached | \
|
git --no-pager diff --name-only --no-color --cached --diff-filter=d |
|
||||||
awk '$1 != "D" && $2 ~ /\.py$/ {print $NF}'
|
# Remove quotations used to surrounding filenames with special characters.
|
||||||
|
sed -e "s/^\"//" -e "s/\"$//g"
|
||||||
)
|
)
|
||||||
|
|
||||||
if [ -n "$FORMAT_FILES" ]; then
|
TARGETS=()
|
||||||
black --quiet "$FORMAT_FILES"
|
while IFS= read -r FILENAME
|
||||||
git add "$FORMAT_FILES"
|
do
|
||||||
|
if [[ "$FILENAME" =~ .*\.py ]]; then
|
||||||
|
TARGETS+=("${FILENAME}")
|
||||||
|
fi
|
||||||
|
done <<< "$STAGED"
|
||||||
|
|
||||||
|
if (( ${#TARGETS[@]} )); then
|
||||||
|
black --quiet "${TARGETS[@]}"
|
||||||
|
git add "${TARGETS[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue