#!/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
    if
        if [ -z "$VIRTUAL_ENV" ] && command -v vagrant >/dev/null && [ -e .vagrant ]; then
            ! vagrant ssh -c 'cd ~/zulip && gitlint'
        else
            ! gitlint
        fi <"$1"
    then
        echo "WARNING: Your commit message does not match Zulip's style guide."
    fi
fi

exit 0
