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.

chore: apply dune fmt and linter refactoring

Auto-formatting and structural improvements from dune fmt across
precommit, publicsuffix, punycode, and requests packages.

+39 -41
+25 -25
bin/main.ml
··· 350 350 let answer = String.trim line in 351 351 answer = "y" || answer = "Y" 352 352 353 + let plural n = if n = 1 then "" else "s" 354 + 355 + let run_fixes ctx affected = 356 + let fixed = Atomic.make 0 in 357 + let errors = Atomic.make 0 in 358 + Eio.Fiber.all 359 + (List.map 360 + (fun d () -> 361 + let backup = Precommit.backup_branch ctx d in 362 + success "%s: backed up to %s" d backup; 363 + match Precommit.rewrite_ai_attribution ctx d with 364 + | Ok _ -> 365 + Atomic.incr fixed; 366 + success "%s: attribution removed" d 367 + | Error msg -> 368 + Atomic.incr errors; 369 + error "%s" msg) 370 + affected); 371 + (Atomic.get fixed, Atomic.get errors) 372 + 353 373 let fix_impl ctx ~dry_run ~yes dirs = 354 374 let dirs = collect_dirs ctx dirs in 355 375 let affected, total_commits, repos_with_issues = ··· 358 378 if total_commits = 0 then success "No AI attribution found in commit history" 359 379 else if dry_run then begin 360 380 info "Would rewrite %d commit%s in %d repo%s" total_commits 361 - (if total_commits = 1 then "" else "s") 362 - repos_with_issues 363 - (if repos_with_issues = 1 then "" else "s"); 381 + (plural total_commits) repos_with_issues (plural repos_with_issues); 364 382 List.iter 365 383 (fun d -> 366 384 let branch = Precommit.current_branch ctx d in ··· 374 392 info "Aborted"; 375 393 exit 0 376 394 end; 377 - let fixed = Atomic.make 0 in 378 - let errors = Atomic.make 0 in 379 - Eio.Fiber.all 380 - (List.map 381 - (fun d () -> 382 - let backup = Precommit.backup_branch ctx d in 383 - success "%s: backed up to %s" d backup; 384 - match Precommit.rewrite_ai_attribution ctx d with 385 - | Ok _ -> 386 - Atomic.incr fixed; 387 - success "%s: attribution removed" d 388 - | Error msg -> 389 - Atomic.incr errors; 390 - error "%s" msg) 391 - affected); 392 395 Format.pp_print_newline Format.std_formatter (); 393 - let n_fixed = Atomic.get fixed in 394 - let n_errors = Atomic.get errors in 396 + let n_fixed, n_errors = run_fixes ctx affected in 395 397 if n_errors > 0 then begin 396 - error "%d repo%s fixed, %d error%s" n_fixed 397 - (if n_fixed = 1 then "" else "s") 398 - n_errors 399 - (if n_errors = 1 then "" else "s"); 398 + error "%d repo%s fixed, %d error%s" n_fixed (plural n_fixed) n_errors 399 + (plural n_errors); 400 400 exit 1 401 401 end 402 - else success "%d repo%s fixed" n_fixed (if n_fixed = 1 then "" else "s") 402 + else success "%d repo%s fixed" n_fixed (plural n_fixed) 403 403 end 404 404 405 405 let yes =
+14 -16
lib/precommit.ml
··· 271 271 else rest 272 272 else abs_path 273 273 274 + let find_self ctx dir entries = 275 + if List.mem ".git" entries then [ dir ] 276 + else if is_inside_git_repo ~cwd:ctx.cwd ~fs:ctx.fs dir then 277 + match git_root ~cwd:ctx.cwd ~fs:ctx.fs dir with 278 + | Some root -> 279 + let _, cwd_path = ctx.cwd in 280 + let cwd_path = 281 + if cwd_path = "" || cwd_path = "." then Sys.getcwd () else cwd_path 282 + in 283 + [ relative ~cwd_path root ] 284 + | None -> [] 285 + else [] 286 + 274 287 let rec git_projects ctx dir = 275 288 let entries = 276 289 try Eio.Path.read_dir Eio.Path.(ctx.cwd / dir) with Eio.Io _ -> [] 277 290 in 278 291 let child_path name = if dir = "." then name else Filename.concat dir name in 279 - (* If dir has .git, include it *) 280 - let self_has_git = List.mem ".git" entries in 281 - (* If dir is inside a git repo (ancestor has .git), return the git root *) 282 - let self = 283 - if self_has_git then [ dir ] 284 - else if is_inside_git_repo ~cwd:ctx.cwd ~fs:ctx.fs dir then 285 - match git_root ~cwd:ctx.cwd ~fs:ctx.fs dir with 286 - | Some git_root -> 287 - let _, cwd_path = ctx.cwd in 288 - let cwd_path = 289 - if cwd_path = "" || cwd_path = "." then Sys.getcwd () else cwd_path 290 - in 291 - [ relative ~cwd_path git_root ] 292 - | None -> [] 293 - else [] 294 - in 292 + let self = find_self ctx dir entries in 295 293 (* Only descend into children if we haven't found a git root yet *) 296 294 let children = 297 295 if self <> [] then []