#!/bin/sh
# foldyard's pre-commit hook: `just lint` (ruff, and mdformat over the Markdown) — a few seconds,
# where `just check` takes a minute. Skip it for one commit with `git commit --no-verify`.
#
# Where it runs: every box created since foldyard.toml's `[box].bootstrap` set it up — in the
# box's own git config, for this checkout and its worktrees only (an older box: recreate it, or
# run that line once) — and on your computer only if you opt in with `just hooks`, which sets it
# in the shared .git/config. Both point here, and core.hooksPath is one setting, so it runs once.
#
# It lints the working tree, not just what is staged, so an unstaged edit can fail a commit that
# doesn't include it: format it, or stash it first.
#
# On your computer it is code the box can write, like any repo hook (docs/security.md): an edit to
# this file or to the `lint` recipe, committed or not, runs at your next commit, before you have
# reviewed it.
if ! command -v just >/dev/null 2>&1; then
    echo "pre-commit: \`just\` isn't on PATH here — not linted (\`just lint\` before you push)" >&2
    exit 0
fi
exec just --justfile "$(git rev-parse --show-toplevel)/justfile" lint
