#!/bin/sh
# SPDX-FileCopyrightText: 2026 Science Against Authoritarianism Contributors
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Free, local CI + OPSEC guard — no cloud, no billing.
# 1) Verifies anonymous git author identity & zero personal/company/path leaks in staged files.
# 2) Runs the read-only audit dashboard (12 gates) before each commit.
# Install once with:  make hooks      (sets git config core.hooksPath .githooks)
# Bypass once with:    git commit --no-verify
cd "$(git rev-parse --show-toplevel)" || exit 1
AUTHOR_EMAIL="$(git var GIT_AUTHOR_IDENT 2>/dev/null | sed -n 's/.*<\([^>]*\)>.*/\1/p')"
if [ -n "$AUTHOR_EMAIL" ] && [ "$AUTHOR_EMAIL" != "contributors@pharos-observatory.invalid" ]; then
  echo "[pre-commit] BLOCKED: non-anonymous git author email detected."
  echo "  Run: git config --local user.name 'Pharos Contributors' && git config --local user.email 'contributors@pharos-observatory.invalid'"
  exit 1
fi
echo "[pre-commit] ./pharos opsec --staged"
PYTHONPATH=src python3 -m pharos.opsec --staged || exit 1
echo "[pre-commit] make dashboard"
exec make dashboard
