#!/bin/sh
[ -f "$(dirname "$0")/_/husky.sh" ] && . "$(dirname "$0")/_/husky.sh"

protected_branch='master'
current_branch=$(git branch --show-current)

if [ "$protected_branch" = "$current_branch" ]
then
    echo "Pushing to $protected_branch is a sin! Instead, create a pull request and repent."
    exit 1 # push will not execute
fi

# Catch deterministic CI failures before this push burns a CI matrix.
# Advisories never block; HOGLI_PREFLIGHT_DISABLED=1 makes it a no-op; no hogli → skip.
if command -v hogli >/dev/null 2>&1
then
    hogli ci:preflight --strict || {
        echo "pre-push: ci:preflight found failures — run 'hogli ci:preflight --fix', resolve, and push again."
        exit 1
    }
fi

exit 0
