precommit#
Pre-commit hook initialization for OCaml projects.
Overview#
This tool sets up git hooks directly for OCaml projects (no Python required):
- pre-commit hook: Automatically formats OCaml code using
dune fmt - commit-msg hook: Removes Claude co-author lines and rejects emojis in commit messages
- .ocamlformat: Creates a default
.ocamlformatfile if missing
Installation#
opam install precommit
Usage#
Initialize hooks#
Run in an OCaml project directory (where dune-project exists):
precommit init
This creates:
.git/hooks/pre-commit- Runsdune fmton staged OCaml files.git/hooks/commit-msg- Filters commit messages.ocamlformat- Default ocamlformat configuration (if missing)
Check status#
precommit status
Shows which hooks are installed. Exit code is 1 if any OCaml project is missing hooks or .ocamlformat.
Check git history#
precommit check
Scans git history for commits with AI attribution patterns.
Recursive operation#
Use -r to operate on all OCaml projects in subdirectories:
precommit init -r
precommit status -r
precommit check -r
Dry run#
To see what would be created without making changes:
precommit init --dry-run
Requirements#
- git
- dune (for code formatting)
Licence#
MIT License. See LICENSE.md for details.