···350350 let answer = String.trim line in
351351 answer = "y" || answer = "Y"
352352353353+let plural n = if n = 1 then "" else "s"
354354+355355+let run_fixes ctx affected =
356356+ let fixed = Atomic.make 0 in
357357+ let errors = Atomic.make 0 in
358358+ Eio.Fiber.all
359359+ (List.map
360360+ (fun d () ->
361361+ let backup = Precommit.backup_branch ctx d in
362362+ success "%s: backed up to %s" d backup;
363363+ match Precommit.rewrite_ai_attribution ctx d with
364364+ | Ok _ ->
365365+ Atomic.incr fixed;
366366+ success "%s: attribution removed" d
367367+ | Error msg ->
368368+ Atomic.incr errors;
369369+ error "%s" msg)
370370+ affected);
371371+ (Atomic.get fixed, Atomic.get errors)
372372+353373let fix_impl ctx ~dry_run ~yes dirs =
354374 let dirs = collect_dirs ctx dirs in
355375 let affected, total_commits, repos_with_issues =
···358378 if total_commits = 0 then success "No AI attribution found in commit history"
359379 else if dry_run then begin
360380 info "Would rewrite %d commit%s in %d repo%s" total_commits
361361- (if total_commits = 1 then "" else "s")
362362- repos_with_issues
363363- (if repos_with_issues = 1 then "" else "s");
381381+ (plural total_commits) repos_with_issues (plural repos_with_issues);
364382 List.iter
365383 (fun d ->
366384 let branch = Precommit.current_branch ctx d in
···374392 info "Aborted";
375393 exit 0
376394 end;
377377- let fixed = Atomic.make 0 in
378378- let errors = Atomic.make 0 in
379379- Eio.Fiber.all
380380- (List.map
381381- (fun d () ->
382382- let backup = Precommit.backup_branch ctx d in
383383- success "%s: backed up to %s" d backup;
384384- match Precommit.rewrite_ai_attribution ctx d with
385385- | Ok _ ->
386386- Atomic.incr fixed;
387387- success "%s: attribution removed" d
388388- | Error msg ->
389389- Atomic.incr errors;
390390- error "%s" msg)
391391- affected);
392395 Format.pp_print_newline Format.std_formatter ();
393393- let n_fixed = Atomic.get fixed in
394394- let n_errors = Atomic.get errors in
396396+ let n_fixed, n_errors = run_fixes ctx affected in
395397 if n_errors > 0 then begin
396396- error "%d repo%s fixed, %d error%s" n_fixed
397397- (if n_fixed = 1 then "" else "s")
398398- n_errors
399399- (if n_errors = 1 then "" else "s");
398398+ error "%d repo%s fixed, %d error%s" n_fixed (plural n_fixed) n_errors
399399+ (plural n_errors);
400400 exit 1
401401 end
402402- else success "%d repo%s fixed" n_fixed (if n_fixed = 1 then "" else "s")
402402+ else success "%d repo%s fixed" n_fixed (plural n_fixed)
403403 end
404404405405let yes =
+14-16
lib/precommit.ml
···271271 else rest
272272 else abs_path
273273274274+let find_self ctx dir entries =
275275+ if List.mem ".git" entries then [ dir ]
276276+ else if is_inside_git_repo ~cwd:ctx.cwd ~fs:ctx.fs dir then
277277+ match git_root ~cwd:ctx.cwd ~fs:ctx.fs dir with
278278+ | Some root ->
279279+ let _, cwd_path = ctx.cwd in
280280+ let cwd_path =
281281+ if cwd_path = "" || cwd_path = "." then Sys.getcwd () else cwd_path
282282+ in
283283+ [ relative ~cwd_path root ]
284284+ | None -> []
285285+ else []
286286+274287let rec git_projects ctx dir =
275288 let entries =
276289 try Eio.Path.read_dir Eio.Path.(ctx.cwd / dir) with Eio.Io _ -> []
277290 in
278291 let child_path name = if dir = "." then name else Filename.concat dir name in
279279- (* If dir has .git, include it *)
280280- let self_has_git = List.mem ".git" entries in
281281- (* If dir is inside a git repo (ancestor has .git), return the git root *)
282282- let self =
283283- if self_has_git then [ dir ]
284284- else if is_inside_git_repo ~cwd:ctx.cwd ~fs:ctx.fs dir then
285285- match git_root ~cwd:ctx.cwd ~fs:ctx.fs dir with
286286- | Some git_root ->
287287- let _, cwd_path = ctx.cwd in
288288- let cwd_path =
289289- if cwd_path = "" || cwd_path = "." then Sys.getcwd () else cwd_path
290290- in
291291- [ relative ~cwd_path git_root ]
292292- | None -> []
293293- else []
294294- in
292292+ let self = find_self ctx dir entries in
295293 (* Only descend into children if we haven't found a git root yet *)
296294 let children =
297295 if self <> [] then []