From 2c0ab1e55edb72c41c606f039415ffc906c0c1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sat, 6 Oct 2018 23:57:33 +0200 Subject: [PATCH] use xargs to prevent globbing in pre-commit.sh --- .pre-commit.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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