Installs pre-commit hooks for OCaml projects that run dune fmt automatically
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Format code and update ocamlformat to 0.28.1

- Update .ocamlformat version in ocaml-csrf and ocaml-spake2
- Update ocaml-csrf for hkdf API changes:
- Use ~salt:"" instead of ~hash:`SHA256 in Hkdf.extract
- Use ~length:32 instead of positional arg in Hkdf.expand
- Apply ocamlformat 0.28.1 formatting across all packages

+19 -14
+8 -9
lib/precommit.ml
··· 60 60 |} 61 61 62 62 let file_exists path = Sys.file_exists path 63 - 64 - let mkdir_p path = 65 - if not (file_exists path) then Unix.mkdir path 0o755 63 + let mkdir_p path = if not (file_exists path) then Unix.mkdir path 0o755 66 64 67 65 let write_file ~dry_run path content = 68 66 if dry_run then Printf.printf "Would create %s\n" path ··· 89 87 Error "No dune-project found. Run this from an OCaml project root." 90 88 else begin 91 89 (* Create .hooks directory *) 92 - if dry_run then Printf.printf "Would create .hooks/\n" 93 - else mkdir_p ".hooks"; 90 + if dry_run then Printf.printf "Would create .hooks/\n" else mkdir_p ".hooks"; 94 91 95 92 (* Write .pre-commit-config.yaml *) 96 93 write_file ~dry_run ".pre-commit-config.yaml" pre_commit_config; ··· 100 97 chmod_exec ~dry_run ".hooks/remove-claude-lines.py"; 101 98 102 99 (* Run pre-commit install *) 103 - let cmd = "pre-commit install --hook-type pre-commit --hook-type commit-msg" in 100 + let cmd = 101 + "pre-commit install --hook-type pre-commit --hook-type commit-msg" 102 + in 104 103 let exit_code = run_command ~dry_run cmd in 105 104 if exit_code <> 0 then 106 - Error (Printf.sprintf "pre-commit install failed with exit code %d" exit_code) 107 - else 108 - Ok () 105 + Error 106 + (Printf.sprintf "pre-commit install failed with exit code %d" exit_code) 107 + else Ok () 109 108 end
+2 -2
lib/precommit.mli
··· 12 12 13 13 val init : dry_run:bool -> unit -> (unit, string) result 14 14 (** [init ~dry_run ()] initializes pre-commit hooks in the current directory. 15 - Creates [.pre-commit-config.yaml] and [.hooks/remove-claude-lines.py], 16 - then runs [pre-commit install]. 15 + Creates [.pre-commit-config.yaml] and [.hooks/remove-claude-lines.py], then 16 + runs [pre-commit install]. 17 17 18 18 If [dry_run] is [true], prints what would be done without making changes. *)
+9 -3
test/test_precommit.ml
··· 11 11 12 12 let test_pre_commit_config_valid () = 13 13 let config = Precommit.pre_commit_config in 14 - Alcotest.(check bool) "starts with repos:" true (String.sub config 0 6 = "repos:"); 15 - Alcotest.(check bool) "contains dune-format" true (contains config "dune-format"); 16 - Alcotest.(check bool) "contains commit-msg" true (contains config "commit-msg") 14 + Alcotest.(check bool) 15 + "starts with repos:" true 16 + (String.sub config 0 6 = "repos:"); 17 + Alcotest.(check bool) 18 + "contains dune-format" true 19 + (contains config "dune-format"); 20 + Alcotest.(check bool) 21 + "contains commit-msg" true 22 + (contains config "commit-msg") 17 23 18 24 let test_remove_claude_lines_valid () = 19 25 let script = Precommit.remove_claude_lines in