#!/bin/sh
# Git post-merge hook: warn-only dirty-protected-path scan on main (WORKSTATE-REF-53 implementation note).
#
# Installed via `make install-git-hooks`. Fires after a successful merge/pull.
# Routine merges with no dirty protected paths exit 0 silently. When the
# merge leaves protected paths dirty on main, the scanner prints a DOCTOR
# advisory pointing the operator at `make doctor LIFECYCLE_ARGS=--json` and
# exits 0 — the publish boundary (pre-push hook + handoff_close_check) is
# the place that actually hard-blocks. This keeps unrelated worktree
# operations from interrupting parallel agents while still surfacing
# ownership-aware remediation guidance.
#
# Pre-WORKSTATE-REF-53 behavior (--block, exit 2 on dirty protected paths) is
# now scoped to pre-push only; see scripts/hooks/git/pre-push and the
# WORKSTATE-REF-53 implementation note task plan section for rationale.
#
# Args: $1=is_squash (1 if squash merge, else 0)

REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)"
if [ -z "$REPO_ROOT" ]; then
    exit 0
fi

python3 "$REPO_ROOT/scripts/hooks/check_main_clean.py" --trigger post-merge --mode doctor || true
exit 0
