#!/bin/sh
set -e

###############################################################################
# Catches a formatting slip before it becomes a commit, rather than after —
# by which point it is a CI failure and a second commit to fix it.
#
# Only checks files with uncommitted changes (`--dirty`), not the whole tree:
# a hook that took as long as the full lint would be a hook people learn to
# skip. Read-only on purpose too — it reports what Pint would change and
# leaves fixing it to you, rather than silently rewriting a file you are
# about to commit without your having seen the diff.
#
# Activated by `composer run setup` (`git config core.hooksPath .githooks`),
# not by being physically inside .git/hooks/ — that directory is not tracked,
# so a hook living only there is never shared with anyone else who clones
# this repository.
###############################################################################

if ! ./vendor/bin/pint --dirty --test; then
    echo >&2
    echo "Pint found formatting issues in the files you are committing." >&2
    echo "Run ./vendor/bin/pint --dirty to fix them, then stage and commit again." >&2
    exit 1
fi
