From ac488fd45f9a077c6f5ab3e7b8e7f9fe005d65b7 Mon Sep 17 00:00:00 2001 From: Elliott Jin Date: Sun, 19 Mar 2017 13:18:10 -0700 Subject: [PATCH] tools: Don't lint in pre-commit hook if no files changed. --- tools/pre-commit | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/pre-commit b/tools/pre-commit index 617b6294cb..14ea067e68 100755 --- a/tools/pre-commit +++ b/tools/pre-commit @@ -9,11 +9,17 @@ # 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 + 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-all --pep8 --force $(cd /srv/zulip && git diff --cached --name-only --diff-filter=ACM) || true' + vcmd="/srv/zulip/tools/lint-all --pep8 --force $changed_files || true" echo "Running lint-all using vagrant..." vagrant ssh -c "$vcmd" else - ./tools/lint-all --pep8 --force $(git diff --cached --name-only --diff-filter=ACM) || true + ./tools/lint-all --pep8 --force $changed_files || true fi exit 0