Installs pre-commit hooks for OCaml projects that run dune fmt automatically
at main 74 lines 1.4 kB view raw view rendered
1# precommit 2 3Pre-commit hook initialization for OCaml projects. 4 5## Overview 6 7This tool sets up git hooks directly for OCaml projects (no Python required): 8- **pre-commit hook**: Automatically formats OCaml code using `dune fmt` 9- **commit-msg hook**: Removes Claude co-author lines and rejects emojis in commit messages 10- **.ocamlformat**: Creates a default `.ocamlformat` file if missing 11 12## Installation 13 14``` 15opam install precommit 16``` 17 18## Usage 19 20### Initialize hooks 21 22Run in an OCaml project directory (where `dune-project` exists): 23 24```bash 25precommit init 26``` 27 28This creates: 29- `.git/hooks/pre-commit` - Runs `dune fmt` on staged OCaml files 30- `.git/hooks/commit-msg` - Filters commit messages 31- `.ocamlformat` - Default ocamlformat configuration (if missing) 32 33### Check status 34 35```bash 36precommit status 37``` 38 39Shows which hooks are installed. Exit code is 1 if any OCaml project is missing hooks or `.ocamlformat`. 40 41### Check git history 42 43```bash 44precommit check 45``` 46 47Scans git history for commits with AI attribution patterns. 48 49### Recursive operation 50 51Use `-r` to operate on all OCaml projects in subdirectories: 52 53```bash 54precommit init -r 55precommit status -r 56precommit check -r 57``` 58 59### Dry run 60 61To see what would be created without making changes: 62 63```bash 64precommit init --dry-run 65``` 66 67## Requirements 68 69- git 70- dune (for code formatting) 71 72## Licence 73 74MIT License. See [LICENSE.md](LICENSE.md) for details.