#!/usr/bin/env bash

set -euo pipefail

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

primary="$(scripts/detect-primary-branch.sh)"
current="$(git branch --show-current)"

if [[ "$current" == "$primary" ]]; then
    printf 'Direct commits on primary are not allowed: %s\n' "$primary" >&2
    exit 1
fi

scope="$(.venv/bin/python scripts/check_change_scope.py --index)"
case "$scope" in
    documentation) exec .venv/bin/python scripts/check-docs.py --index ;;
    full) exec scripts/check-fast.sh ;;
    *) printf 'Unknown check scope: %s\n' "$scope" >&2; exit 1 ;;
esac
