#!/bin/sh
# Runs the full local gate before anything is pushed: lint, version consistency, every test suite and the
# cross-version Python wheel check (`make verify`). Pushing a v* tag also checks that the tag matches the
# package versions. Enable once per clone:  git config core.hooksPath .githooks
# Bypass in an emergency:                   SKIP_VERIFY=1 git push
[ -n "$SKIP_VERIFY" ] && { echo "pre-push: SKIP_VERIFY set, not running make verify" >&2; exit 0; }

while read -r _local_ref _local_sha remote_ref _remote_sha; do
  case "$remote_ref" in
    refs/tags/v*)
      tag="${remote_ref#refs/tags/}"
      make versions TAG="$tag" || { echo "pre-push: tag $tag does not match the package versions" >&2; exit 1; }
      ;;
  esac
done

echo "pre-push: running make verify (set SKIP_VERIFY=1 to skip)" >&2
make verify || { echo "pre-push: make verify failed, nothing was pushed" >&2; exit 1; }
