From 49ae9c1e44ea11fb6a8c281d516c262c84aa5713 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 3 Aug 2018 00:14:49 +0000 Subject: [PATCH] pre-commit: Fix shellcheck warnings. In tools/pre-commit line 18: if [ -z "$VIRTUAL_ENV" ] && `which vagrant > /dev/null` && [ -e .vagrant ]; then ^-- SC2092: Remove backticks to avoid executing output. ^-- SC2006: Use $(..) instead of legacy `..`. ^-- SC2230: which is non-standard. Use builtin 'command -v' instead. In tools/pre-commit line 23: ./tools/lint --no-gitlint --force $changed_files || true ^-- SC2086: Double quote to prevent globbing and word splitting. Signed-off-by: Anders Kaseorg --- tools/pre-commit | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/pre-commit b/tools/pre-commit index 3feeff01d5..9807744859 100755 --- a/tools/pre-commit +++ b/tools/pre-commit @@ -9,17 +9,20 @@ # contains your provisioned Zulip development environment, the linter # will automatically be run through `vagrant ssh`. -changed_files=$(git diff --cached --name-only --diff-filter=ACM) -if [ -z "$changed_files" ]; then +changed_files=() +while read -r -d '' f; do + changed_files+=("$f") +done < <(git diff -z --cached --name-only --diff-filter=ACM) +if [ ${#changed_files} -eq 0 ]; then echo "No changed files to lint." exit 0 fi -if [ -z "$VIRTUAL_ENV" ] && `which vagrant > /dev/null` && [ -e .vagrant ]; then - vcmd="/srv/zulip/tools/lint --no-gitlint --force $changed_files || true" +if [ -z "$VIRTUAL_ENV" ] && command -v vagrant > /dev/null && [ -e .vagrant ]; then + vcmd="/srv/zulip/tools/lint --no-gitlint --force $(printf '%q ' "${changed_files[@]}") || true" echo "Running lint using vagrant..." vagrant ssh -c "$vcmd" else - ./tools/lint --no-gitlint --force $changed_files || true + ./tools/lint --no-gitlint --force "${changed_files[@]}" || true fi exit 0