Something went wrong. Try again.
A local Git merge queue with content-bound gate verdicts
Something went wrong. Try again.
1.4 kB · 37 lines
OCaml
at main
1234567891011121314151617181920212223242526272829303132333435363738module M = Merge_queue
type phase = Preparing | Prepared | Committed | Aborted
(* The probes the transaction names, as Git gives its refs: one line "<old> SP <new> SP <ref>" 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