#!/usr/bin/env bash

# This hook runs gitlint on your commit message.

# If your machine contains a provisioned Zulip development environment, the
# linter will be invoked through `vagrant ssh`.

# Do not invoke gitlint if commit message is empty
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

exit 0
