#!/bin/sh
# SPDX-FileCopyrightText: 2026 Science Against Authoritarianism Contributors
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Free, local CI + OPSEC push guard — refuses pushing to any remote URL that
# matches a personal or company identifier digest, then runs `make verify-offline`.
# Install once with:  make hooks
# Bypass once with:    git push --no-verify
cd "$(git rev-parse --show-toplevel)" || exit 1
REMOTE_URL="$2"
if [ -n "$REMOTE_URL" ]; then
  PYTHONPATH=src python3 -c "import sys; from pharos import release_bundle as rb; hits = rb.scan_text_for_identity_leaks(sys.argv[1]); sys.exit(2 if hits else 0)" "$REMOTE_URL"
  if [ $? -eq 2 ]; then
    echo "[pre-push] BLOCKED: remote URL matches a personal or company identity digest. Never push Pharos to personal/company remotes."
    exit 1
  fi
fi
echo "[pre-push] ./pharos opsec"
PYTHONPATH=src python3 -m pharos.opsec || exit 1
echo "[pre-push] make verify-offline"
exec make verify-offline
