Installs pre-commit hooks for OCaml projects that run dune fmt automatically
OCaml 89.3%
Perl 3.6%
Python 2.4%
Dune 1.3%
Raku 0.9%
Other 2.5%
59 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-precommit https://tangled.org/did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-precommit
git@git.recoil.org:gazagnaire.org/ocaml-precommit git@git.recoil.org:did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-precommit

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

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 .ocamlformat file 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 - Runs dune fmt on 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.