#!/bin/sh
# Run the checks declared in .pre-commit-config.yaml.
#
# Invoked from .githooks/pre-commit because core.hooksPath points here and git
# ignores .git/hooks while it does. If the config is present, the runner must
# be too: not running a declared check is not a pass (exit 3).
set -e

CONFIG="$(git rev-parse --show-toplevel)/.pre-commit-config.yaml"
if [ -f "$CONFIG" ]; then
  if command -v pre-commit >/dev/null 2>&1; then
    pre-commit run --hook-stage pre-commit || exit 1
  else
    echo "  -> .pre-commit-config.yaml is present but pre-commit is not installed." >&2
    echo "     Run: uv tool install pre-commit" >&2
    echo "     Not running a declared check is not a pass." >&2
    exit 3
  fi
fi
