#!/usr/bin/env bash
# Tracked pre-push hook. Wired up automatically by the hatch build hook on
# `uv sync` (it sets core.hooksPath to this directory). Delegates to pre-commit
# in the project's .venv. Unlike a `pre-commit install` generated hook, the
# python path is resolved at run time, so this file is portable across clones.
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-push)
HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")

INSTALL_PYTHON="$(git rev-parse --show-toplevel)/.venv/bin/python"
if [ -x "$INSTALL_PYTHON" ]; then
    exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
elif command -v pre-commit > /dev/null; then
    exec pre-commit "${ARGS[@]}"
else
    echo '`pre-commit` not found. Run `uv sync` to set up the environment.' 1>&2
    exit 1
fi
