#!/usr/bin/env sh
#
# Refuse to push with a red suite. Installed by bin/install-hooks.
#
# The suite runs in the php-fpm container, which is where Composer and the extensions live.
# It has no database and finishes in well under a second, so it costs nothing on a push.
#
# There is deliberately no pre-commit hook: the workflow commits once per review round and
# amends small corrections, and a gate there would tax exactly those. See docs/WORKFLOW.md.
#
# Bypass with `git push --no-verify` when you know why.

set -e

cd "$( git rev-parse --show-toplevel )"

if [ "$( docker inspect -f '{{.State.Running}}' raktar24-php-fpm 2> /dev/null )" != 'true' ]; then
	echo 'pre-push: raktar24-php-fpm is not running — start it with `docker compose up -d`,'
	echo '          or push with --no-verify if you know the suite is green.'
	exit 1
fi

echo 'pre-push: composer test'
docker exec raktar24-php-fpm composer test
