module M = Merge_queue type phase = Preparing | Prepared | Committed | Aborted (* The probes the transaction names, as Git gives its refs: one line " SP SP " each (githooks(5)). *) let probes stdin = List.filter_map (fun line -> match String.split_on_char ' ' line with | [ _; _; name ] -> ( match M.Ref_name.of_string name with | Some (M.Ref_name.Probe _ as r) -> Some r | Some _ | None -> None) | _ -> None) (String.split_on_char '\n' stdin) (* A transaction that names a probe of mq init or mq doctor is answered in the repository the hook runs in, whatever its phase. One that names none is not looked at: Git runs the hook at every phase of every transaction. *) let answer ctx ~stdin = match (probes stdin, ctx.Command.environment, ctx.directory) with | [], _, _ -> () | probes, Ok environment, Ok dir -> ( match Repo.discover environment dir with | Ok location -> let fs = (Eio.Stdenv.fs ctx.env :> Eio.Fs.dir_ty Eio.Path.t) in List.iter (Repo.answer_probe ~fs location) probes | Error _ -> ()) | _, Error _, _ | _, _, Error _ -> () let run ctx _ ~phase ~stdin = (try answer ctx ~stdin with Eio.Io _ -> ()); (match phase with | Committed -> Command.hook_committed ctx stdin | Preparing | Prepared | Aborted -> ()); 0