2018-12-18 02:08:53 +01:00
|
|
|
#!/usr/bin/env bash
|
2016-08-17 22:03:54 +02:00
|
|
|
|
2017-04-21 23:07:06 +02:00
|
|
|
# This hook runs the Zulip code linter ./tools/lint and returns true
|
2016-08-17 22:03:54 +02:00
|
|
|
# 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`.
|
|
|
|
|
2018-08-03 02:14:49 +02:00
|
|
|
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
|
2017-03-19 21:18:10 +01:00
|
|
|
echo "No changed files to lint."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-10-15 04:55:57 +02:00
|
|
|
if [ -z "$VIRTUAL_ENV" ] && command -v vagrant >/dev/null && [ -e .vagrant ]; then
|
2021-03-02 20:59:19 +01:00
|
|
|
vcmd="/srv/zulip/tools/lint --skip=gitlint --skip-provision-check $(printf '%q ' "${changed_files[@]}") || true"
|
2017-04-21 23:07:06 +02:00
|
|
|
echo "Running lint using vagrant..."
|
2016-08-17 22:03:54 +02:00
|
|
|
vagrant ssh -c "$vcmd"
|
|
|
|
else
|
2021-03-02 20:59:19 +01:00
|
|
|
./tools/lint --skip=gitlint --skip-provision-check "${changed_files[@]}" || true
|
2016-08-17 22:03:54 +02:00
|
|
|
fi
|
|
|
|
exit 0
|