#!/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)"
[[ "$current" == "$primary" ]] || {
    printf 'Merge commits are permitted only on primary: %s\n' "$primary" >&2
    exit 1
}

scripts/check-version.py --index
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-full.sh ;;
    *) printf 'Unknown check scope: %s\n' "$scope" >&2; exit 1 ;;
esac
