Select the types of activity you want to include in your feed.
precommit: add .ocamlformat check and creation
- Add has_ocamlformat field to hook_status type - init creates .ocamlformat (version 0.28.1) if missing - status displays .ocamlformat column - Exit code 1 if any OCaml project missing .ocamlformat
···4141 (fun d ->
4242 let s = Precommit.status_in_dir d in
4343 if s.is_ocaml_project && s.is_git_repo then
4444- if not (s.has_pre_commit && s.has_commit_msg) then begin
4444+ if not (s.has_pre_commit && s.has_commit_msg && s.has_ocamlformat) then begin
4545 or_die (Precommit.init_in_dir ~dry_run d);
4646 let verb = if dry_run then "Would initialise" else "Initialised" in
4747 Printf.printf "%s: %s\n" d verb
···5555 `S Manpage.s_description;
5656 `P
5757 "Install git hooks that run $(b,dune fmt) before commit and remove \
5858- Claude attribution from commit messages.";
5858+ Claude attribution from commit messages. Also creates \
5959+ $(b,.ocamlformat) if missing.";
5960 `S Manpage.s_examples;
6061 `P "Initialise hooks in the current directory:";
6162 `Pre " precommit init";
···7374let pp_check b = if b then "\027[32m✓\027[0m" else "\027[31m✗\027[0m"
74757576let pp_status name (s : Precommit.hook_status) =
7676- Printf.printf "%s %s %s %s\n"
7777+ Printf.printf "%s %s %s %s %s\n"
7778 (pp_check s.has_pre_commit)
7879 (pp_check s.has_commit_msg)
8080+ (pp_check s.has_ocamlformat)
7981 (pp_check s.is_ocaml_project)
8082 name
81838284let status recursive dirs =
8385 let dirs = collect_dirs ~recursive dirs in
8484- Printf.printf "pre-commit commit-msg ocaml directory\n";
8585- Printf.printf "---------- ---------- ----- ---------\n";
8686+ Printf.printf "pre-commit commit-msg ocamlformat ocaml directory\n";
8787+ Printf.printf "---------- ---------- ----------- ----- ---------\n";
8688 let missing = ref false in
8789 List.iter
8890 (fun d ->
8991 let s = Precommit.status_in_dir d in
9092 pp_status d s;
9193 if s.is_ocaml_project && s.is_git_repo then
9292- if not (s.has_pre_commit && s.has_commit_msg) then missing := true)
9494+ if not (s.has_pre_commit && s.has_commit_msg && s.has_ocamlformat) then
9595+ missing := true)
9396 dirs;
9497 if !missing then exit 1
9598···100103 `S Manpage.s_description;
101104 `P "Show which directories have hooks installed.";
102105 `P
103103- "Columns show: pre-commit hook, commit-msg hook, is OCaml project. \
104104- Exit code is 1 if any OCaml project is missing hooks.";
106106+ "Columns show: pre-commit hook, commit-msg hook, .ocamlformat file, is \
107107+ OCaml project. Exit code is 1 if any OCaml project is missing hooks \
108108+ or .ocamlformat.";
105109 `S Manpage.s_examples;
106110 `P "Check status of all projects under src/:";
107111 `Pre " precommit status -r src/";
+13
lib/precommit.ml
···5555exit 0
5656|}
57575858+let default_ocamlformat = {|version = 0.28.1
5959+|}
6060+5861let file_exists path = Sys.file_exists path
59626063let mkdir_p path =
···8285let init_in_dir ~dry_run dir =
8386 let dune_project = Filename.concat dir "dune-project" in
8487 let git_dir_path = Filename.concat dir ".git" in
8888+ let ocamlformat_path = Filename.concat dir ".ocamlformat" in
8589 if not (file_exists dune_project) then
8690 Error (Printf.sprintf "%s: No dune-project found" dir)
8791 else if not (file_exists git_dir_path) then
···115119 write_file ~dry_run commit_msg_path commit_msg_hook;
116120 chmod_exec ~dry_run commit_msg_path;
117121122122+ (* Create .ocamlformat if missing *)
123123+ if not (file_exists ocamlformat_path) then
124124+ write_file ~dry_run ocamlformat_path default_ocamlformat;
125125+118126 Ok ()
119127120128let init ~dry_run () = init_in_dir ~dry_run "."
···122130type hook_status = {
123131 has_pre_commit : bool;
124132 has_commit_msg : bool;
133133+ has_ocamlformat : bool;
125134 is_ocaml_project : bool;
126135 is_git_repo : bool;
127136}
···129138let status_in_dir dir =
130139 let dune_project = Filename.concat dir "dune-project" in
131140 let git_dir_path = Filename.concat dir ".git" in
141141+ let ocamlformat_path = Filename.concat dir ".ocamlformat" in
132142 let is_ocaml_project = file_exists dune_project in
133143 let is_git_repo = file_exists git_dir_path in
144144+ let has_ocamlformat = file_exists ocamlformat_path in
134145 if not is_git_repo then
135146 {
136147 has_pre_commit = false;
137148 has_commit_msg = false;
149149+ has_ocamlformat;
138150 is_ocaml_project;
139151 is_git_repo;
140152 }
···156168 {
157169 has_pre_commit = file_exists pre_commit_path;
158170 has_commit_msg = file_exists commit_msg_path;
171171+ has_ocamlformat;
159172 is_ocaml_project;
160173 is_git_repo;
161174 }
+2
lib/precommit.mli
···1717type hook_status = {
1818 has_pre_commit : bool;
1919 has_commit_msg : bool;
2020+ has_ocamlformat : bool;
2021 is_ocaml_project : bool;
2122 is_git_repo : bool;
2223}
···3031 Creates:
3132 - [.git/hooks/pre-commit] - runs [dune fmt] on staged OCaml files
3233 - [.git/hooks/commit-msg] - checks for emojis and removes Claude attribution
3434+ - [.ocamlformat] - if missing, creates with default version
33353436 If [dry_run] is [true], prints what would be done without making changes.
3537