#!/bin/sh
# Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
#
# Registered by `scripts/setup-git-hooks.mjs` via `core.hooksPath=.githooks`,
# which `pnpm install` runs. Cheap by construction: with no pending marker it
# exits before doing any work, which is every commit that did not just merge a
# generator-owned artifact (#4675).
#
# One commit is exempt, and only one: a MERGE commit finished BY HAND, with
# `MERGE_HEAD` present at commit time — a conflicted merge an operator
# resolves and finishes with `git commit`. That commit records a deferral
# instead of being refused; the immediately following commit must discharge
# it, and `.githooks/pre-push` refuses the push if none ever does (#8047).
#
# The sanctioned landing sequence (`scripts/pm/os-regen-merge.sh`) does NOT
# hit that exemption: its step 1 merge auto-commits with no hook run at all
# (see below), so the marker is untouched going into step 3, whose commit is
# an ORDINARY one this hook refuses on purpose — that refusal is the designed
# collection point, "what main brought" read apart from "what the change
# produces" by the fallback it prints, not a deferral.
#
# ⚠️ git does not run this hook for a merge it completes ITSELF — only for one
# you finish with `git commit`. A clean auto-committed merge therefore lands
# with the marker untouched and the refusal falls on the next commit, which is
# the same collection point either way.

if [ -z "$OS_SKIP_REGEN_CHECK" ]; then
  node "$(git rev-parse --show-toplevel)/scripts/check-regen-pending.mjs" || exit 1
fi
