Something went wrong. Try again.
Git format in pure OCaml
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546(* Copyright (c) 2024-2026 Thomas Gazagnaire <thomas@gazagnaire.org>
Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *)
(** Fast-forward a fetched commit into the current branch, functored over a {!Store.S}. *)
module Hash = Object_hash
type outcome = | Up_to_date | Fast_forwarded of Checkout.report | Not_fast_forward of { local : Hash.t; fetched : Hash.t }
module Make (S : Checkout.S) = struct module C = Checkout.Make (S)
let fast_forward repo ~fetched = match S.head repo with | Error (`Msg m) -> Error (`Msg m) | Ok None -> Error (`Msg "pull: no local commits to fast-forward (use clone for an empty \ repository)") | Ok (Some local) when Hash.equal local fetched -> Ok Up_to_date | Ok (Some local) -> if S.is_ancestor repo ~ancestor:local ~descendant:fetched then ( match C.fast_forward repo ~base:local ~target:fetched with | Error _ as e -> e | Ok report -> S.advance_head repo fetched; Ok (Fast_forwarded report)) else Ok (Not_fast_forward { local; fetched })end