#!/usr/bin/env bash
set -euo pipefail

export PATH="$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin:$PATH"

repo_root="$(git rev-parse --show-toplevel)"
cd "$repo_root"

run() {
  printf '\n==> %s\n' "$*"
  "$@"
}

printf 'Checking repository before commit in %s\n' "$repo_root"

run git status --short
run git diff --check
run git diff --cached --check
run git diff --cached --stat
run git diff --stat

run uv run ruff check .
run uv run ruff format . --check
run uv run pyright
run uv run python -m unittest discover -s tests
run uv run src-auth-perms-sync --help

printf '\nPre-commit quality checks passed.\n'
