#!/bin/bash

# Block direct pushes to main — require PRs
protected_branch="main"
current_branch=$(git symbolic-ref --short HEAD 2>/dev/null)

while read local_ref local_oid remote_ref remote_oid; do
  if echo "$remote_ref" | grep -q "refs/heads/${protected_branch}$"; then
    if [ "$current_branch" = "$protected_branch" ]; then
      echo "ERROR: Direct push to '$protected_branch' is not allowed."
      echo "Create a feature branch and open a pull request instead."
      exit 1
    fi
  fi
done

# Check for JavaScript files in src/ (strict TypeScript project)
npx tsx scripts/check-no-js-in-src.ts

# Run full validation with coverage
npm run spellcheck && npm run typecheck && npm run test:unit -- --coverage && npm run build
