ludic/tools/git-hooks/pre-commit
Orkuncakilkaya 709465cdd8
All checks were successful
bootstrap / cfree-fixpoint (push) Successful in 12s
ci / build-and-test (push) Successful in 50s
commit-lint / conventional-commits (push) Successful in 3s
build(git-hooks): enforce Conventional Commits via a hook + CI, record history decision
The convention was documented in CONTRIBUTING.md but nothing enforced it, and no
decision was on record for the pre-self-hosting `Phase` history.

- tools/git-hooks/commit-msg — rejects a summary that is not a Conventional
  Commit. tools/git-hooks/lib.sh holds the single rule (types, scope, `!`, and
  the merge/revert/autosquash exemptions) so the hook and CI cannot drift.
- tools/git-hooks/lint-range.sh — lints a commit range with that same rule.
- .forgejo/workflows/commit-lint.yml — runs it over the new commits on every
  push and PR, as the backstop for contributors who have not enabled the hook.
- Fix the pre-commit hook, which pointed at the old build/ludic-fmt path (the
  toolchain moved to bin/) and so silently no-op'd; it now finds bin/ludic-fmt.
- CONTRIBUTING.md — full type/scope table, the one-line enable
  (`git config core.hooksPath tools/git-hooks`), and a **Git history** section
  recording the decision: leave the pushed `Phase`-era history as-is (a rewrite
  is destructive and non-reversible for anyone who cloned); enforce the
  convention going forward; let #33's first release tag double as the clean `v0`
  baseline that brackets the old prefix without touching a commit.

Verified: the hook accepts feat/fix/ci/refactor(!)/merge/revert and rejects
"added regex" / "Fix bug" / "WIP"; lint-range passes recent history and flags
the old `Phase 8b:` commit.

Closes #34

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-30 23:30:45 +03:00

31 lines
906 B
Bash
Executable file

#!/bin/sh
# Reject a commit that contains unformatted Ludic — in source or in the ```ludic
# fences of a Markdown file.
#
# Enable this and the commit-msg hook together with:
#
# git config core.hooksPath tools/git-hooks
#
# Checks only the files being committed, so it stays fast on a big tree.
set -e
ROOT=$(git rev-parse --show-toplevel)
FMT="$ROOT/bin/ludic-fmt"
[ -x "$FMT" ] || exit 0 # toolchain not built: do not block the commit
FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(ludic|md|markdown)$' || true)
[ -z "$FILES" ] && exit 0
UNFORMATTED=""
for f in $FILES; do
[ -f "$ROOT/$f" ] || continue
"$FMT" --check -q "$ROOT/$f" >/dev/null 2>&1 || UNFORMATTED="$UNFORMATTED $f"
done
if [ -n "$UNFORMATTED" ]; then
echo "unformatted Ludic:"
for f in $UNFORMATTED; do echo " $f"; done
echo
echo "fix with: build/ludic-fmt -w$UNFORMATTED"
exit 1
fi