From 4a8074000ce3b65827ba5be0da82c295f2551e62 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 3 Aug 2018 00:14:48 +0000 Subject: [PATCH] commit-msg: Fix shellcheck warnings. In tools/commit-msg line 9: if [ $(grep '^[^#]' .git/COMMIT_EDITMSG --count) -ne 0 ]; then ^-- SC2046: Quote this to prevent word splitting. In tools/commit-msg line 10: lint_cmd="cd ~/zulip && cat \"$1\" | python -m gitlint.cli" ^-- SC2089: Quotes/backslashes will be treated literally. Use an array. In tools/commit-msg line 11: 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/commit-msg line 14: $lint_cmd ^-- SC2090: Quotes/backslashes in this variable will not be respected. In tools/commit-msg line 17: if [ $? -ne 0 ]; then ^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. Signed-off-by: Anders Kaseorg --- tools/commit-msg | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/commit-msg b/tools/commit-msg index b143428ca7..ad3549b52c 100755 --- a/tools/commit-msg +++ b/tools/commit-msg @@ -6,15 +6,15 @@ # linter will be invoked through `vagrant ssh`. # Do not invoke gitlint if commit message is empty -if [ $(grep '^[^#]' .git/COMMIT_EDITMSG --count) -ne 0 ]; then - lint_cmd="cd ~/zulip && cat \"$1\" | python -m gitlint.cli" - if [ -z "$VIRTUAL_ENV" ] && `which vagrant > /dev/null` && [ -e .vagrant ]; then - vagrant ssh -c "$lint_cmd" - else - $lint_cmd - fi - - if [ $? -ne 0 ]; then +if grep -q '^[^#]' "$1"; then + lint_cmd="cd ~/zulip && python -m gitlint.cli" + if \ + if [ -z "$VIRTUAL_ENV" ] && command -v vagrant > /dev/null && [ -e .vagrant ]; then + ! vagrant ssh -c "$lint_cmd" + else + ! eval "$lint_cmd" + fi < "$1" + then echo "WARNING: Your commit message does not match Zulip's style guide." fi fi