#!/bin/sh
# Runs the same checks as CI before pushing.
#
# Deletion-only pushes carry no code (git reports an all-zero local
# sha for each deleted ref on stdin), so skip the checks for them.

deleting_only=1
while read -r local_ref local_sha remote_ref remote_sha; do
    case "$local_sha" in
        *[!0]*) deleting_only=0 ;;
    esac
done

if [ "$deleting_only" -eq 1 ]; then
    exit 0
fi

if ! command -v just >/dev/null 2>&1; then
    echo "pre-push hook: 'just' is required. Install it with 'brew install just'." >&2
    exit 127
fi

just check
