#!/bin/sh
# Git post-commit hook: best-effort active-task SHA refresh plus warn-only dirty scan.
#
# Installed via `make install-git-hooks`. Never fails the commit: post-commit
# is observability/housekeeping only. When git-lfs is present we still chain to
# its post-commit hook so repos using LFS keep the default follow-up behavior.

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

# Resolve guard scripts relative to this hook's own location (one level up from
# the git/ hook dir), not $REPO_ROOT — works in nested-source / hoisted consumer
# layouts where the git root is not the shared hook source (implementation note ask G).
HOOK_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
GUARD_DIR="$(dirname "$HOOK_DIR")"

if command -v git-lfs >/dev/null 2>&1; then
    git lfs post-commit "$@" >/dev/null 2>&1 || true
fi

python3 "$GUARD_DIR/_post_commit_refresh_sha.py" || true
python3 "$GUARD_DIR/check_main_clean.py" --trigger post-commit || true
exit 0
