diff --git a/.pre-commit.sh b/.pre-commit.sh index 30f09eb9..0e0e3c1a 100755 --- a/.pre-commit.sh +++ b/.pre-commit.sh @@ -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