#!/bin/sh
# Blocks the commit if what is staged contains game data.
# Enable it once per clone with: git config core.hooksPath .githooks
top=$(git rev-parse --show-toplevel) || exit 1
export PYTHONPATH="$top/src"

# First interpreter with Python >= 3.13. "py -3.13" is two words: $python goes unquoted.
for python in "py -3.13" python3 python; do
    # shellcheck disable=SC2086
    if $python -c 'import sys; sys.exit(sys.version_info < (3, 13))' >/dev/null 2>&1; then
        # -P: without the cwd on sys.path, a .py in the repo root cannot shadow the stdlib.
        # -X utf8: on Windows, piped output (Git Bash, IDE) would otherwise be cp1252.
        # shellcheck disable=SC2086
        exec $python -X utf8 -P -m ngb_tools.hygiene --staged
    fi
done

echo "pre-commit: Python >= 3.13 is required (tried: py -3.13, python3, python)." >&2
exit 1
