Files
zulip/tools/pre-commit
Anders Kaseorg 392175d6e8 Use #!/usr/bin/env for bash shebangs.
/bin/sh and /usr/bin/env are the only two binaries that NixOS provides
at a fixed path (outside a buildFHSUserEnv sandbox).

This discussion was split from #11004.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2018-12-17 17:21:08 -08:00

29 lines
963 B
Bash
Executable File

#!/usr/bin/env bash
# This hook runs the Zulip code linter ./tools/lint and returns true
# regardless of linter results so that your commit may continue.
# Messages from the linter will be printed out to the screen.
#
# If you are running this one machine hosting a Vagrant guest that
# contains your provisioned Zulip development environment, the linter
# will automatically be run through `vagrant ssh`.
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" ] && 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
fi
exit 0