#!/bin/sh
# Code Guardian – Git Pre-Push Hook (self-locating, machine-independent)
# Installed automatically via `npm run setup-hooks` or by the VS Code extension.
#
# Runs the Node.js checker before every git push.
# If error-severity issues are found, the push is BLOCKED (exit 1).

REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" || exit 0

# Prefer the bundled checker next to this repo; fall back to the self-contained
# copy installed by the VS Code extension.
if [ -f "$REPO_ROOT/git-hooks/checkPush.js" ]; then
  CHECKER="$REPO_ROOT/git-hooks/checkPush.js"
elif [ -f "$REPO_ROOT/.git/hooks/code-guardian/git-hooks/checkPush.cjs" ]; then
  CHECKER="$REPO_ROOT/.git/hooks/code-guardian/git-hooks/checkPush.cjs"
else
  echo ""
  echo "⚠️  Code Guardian: checkPush.js not found – skipping pre-push check."
  echo ""
  exit 0
fi

MSYS_NO_PATHCONV=1 node "$CHECKER"
exit $?
