#!/usr/bin/env bash
# Thin dispatcher — the actual PORT-DEBT direct-main leg is
# scripts/port-debt-direct-main.sh (port-debt-scanner-missed-rows, 2026-08-26),
# shared verbatim with .githooks/post-merge: a commit made straight on main
# and a merge made straight on main are the SAME hazard, checked by the SAME
# predicate. See that script's docstring for the full rationale, including
# why BOTH hooks exist (post-commit is never invoked by `git merge` —
# githooks(5) — so a merge-only design would still miss a hand `git merge`
# run straight on main).
set -uo pipefail
TOPLEVEL="$(git rev-parse --show-toplevel 2>/dev/null)" || exit 0
# REPO-COUPLING GUARD (precommit-hook-not-cwd-portable, 2026-08-26): this
# scan is {{PROJECT_SLUG}}-specific in meaning (it watches {{PROJECT_SLUG}}'s OWN merge-window
# discipline) and its script lives ONLY in {{PROJECT_SLUG}}'s checkout. TOPLEVEL is
# whatever repo is actually being committed to, which is not {{PROJECT_SLUG}} for a
# fixture repo or install-hooks.sh's own self-test that points
# core.hooksPath here — `exec`-ing a script that is not there would fail
# loudly on every such commit. DECISION: must fire ONLY in {{PROJECT_SLUG}}, so this
# checks for the script before dispatching rather than relying solely on
# the shared script's own "branch is main" belt check, which only helps
# once the script can be found and run at all.
[ -f "$TOPLEVEL/scripts/port-debt-direct-main.sh" ] || {
  echo "post-commit: SKIP — port-debt scan (scripts/port-debt-direct-main.sh not found in $TOPLEVEL; not this {{PROJECT_SLUG}} checkout)" >&2
  exit 0
}
exec "$TOPLEVEL/scripts/port-debt-direct-main.sh" post-commit
