#!/bin/sh
# Pre-push: the docs pages under apps/docs/content are generated from work/1
# by `bun run sync`, and deploy.yml publishes whatever main holds. Regenerate
# them now and refuse the push if the result differs from the tree, so a
# solution never lands without its page (or with a stale `## Solution`).
#
# Bypass for a deliberate partial push: git push --no-verify
set -eu

cd "$(git rev-parse --show-toplevel)"
report=$(bun run --silent sync)

changed=$(git status --porcelain -- apps/docs/content)
if [ -n "$changed" ]; then
  printf '%s\n' "$report" | grep -v 'skipped (in sync)' >&2
  printf '\npre-push: apps/docs/content is out of sync with work/1 — commit the regenerated pages:\n%s\n' "$changed" >&2
  exit 1
fi
