use xargs to prevent globbing in pre-commit.sh

This commit is contained in:
Martin Pépin 2018-10-06 23:57:33 +02:00
parent fc4b852bde
commit 2c0ab1e55e

View file

@ -12,6 +12,7 @@ checker_dirty=0
# Working? -> Stash unstaged changes, run it, pop stash
STAGED_PYTHON_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".py$")
# Formatter: black
printf "> black ... "
@ -23,8 +24,8 @@ if type black &>/dev/null; then
BLACK_OUTPUT="/tmp/gc-black-output.log"
touch $BLACK_OUTPUT
if ! black --check "$STAGED_PYTHON_FILES" &>$BLACK_OUTPUT; then
black "$STAGED_PYTHON_FILES" &>$BLACK_OUTPUT
if ! echo "$STAGED_PYTHON_FILES" | xargs -d'\n' black --check &>$BLACK_OUTPUT; then
echo "$STAGED_PYTHON_FILES" | xargs -d'\n' black &>$BLACK_OUTPUT
tail -1 $BLACK_OUTPUT
formatter_updated=1
else
@ -47,8 +48,8 @@ if type isort &>/dev/null; then
ISORT_OUTPUT="/tmp/gc-isort-output.log"
touch $ISORT_OUTPUT
if ! isort --check-only "$STAGED_PYTHON_FILES" &>$ISORT_OUTPUT; then
isort "$STAGED_PYTHON_FILES" &>$ISORT_OUTPUT
if ! echo "$STAGED_PYTHON_FILES" | xargs -d'\n' isort --check-only &>$ISORT_OUTPUT; then
echo "$STAGED_PYTHON_FILES" | xargs -d'\n' isort &>$ISORT_OUTPUT
printf "Reformatted.\n"
formatter_updated=1
else
@ -71,7 +72,7 @@ if type flake8 &>/dev/null; then
FLAKE8_OUTPUT="/tmp/gc-flake8-output.log"
touch $FLAKE8_OUTPUT
if ! flake8 "$STAGED_PYTHON_FILES" &>$FLAKE8_OUTPUT; then
if ! echo "$STAGED_PYTHON_FILES" | xargs -d'\n' flake8 &>$FLAKE8_OUTPUT; then
printf "FAIL\n"
cat $FLAKE8_OUTPUT
checker_dirty=1