Something went wrong. Try again.
Git format in pure OCaml
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667(* 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. *)
open Cmdliner
let sha_arg = let doc = "Hex SHA-1 of the commit to drop." in Arg.(required & pos 0 (some string) None & info [] ~docv:"SHA" ~doc)
let mainline_arg = let doc = "For a merge commit, the 1-indexed parent to keep. Required when $(b,SHA) \ is a merge; every other side of the merge becomes unreachable from \ $(b,--ref). Rejected when $(b,SHA) is not a merge." in Arg.(value & opt (some int) None & info [ "m"; "mainline" ] ~docv:"N" ~doc)
let run ~repo_path ~sha ~mainline ~ref_name () = Common.with_repo repo_path @@ fun repo -> match Common.resolve_target_ref repo ref_name with | Error (`Msg m) -> Common.pp_error Fmt.stderr m; `Error (false, m) | Ok ref_name -> ( match Common.parse_sha ~repo sha with | Error (`Msg m) -> Common.pp_error Fmt.stderr m; `Error (false, m) | Ok commit -> Git_eio.Rewrite.drop_commit repo ~commit ?mainline ~ref_name () |> Common.report_rewrite_result)
let term = Term.( ret (const (fun () repo_path sha mainline ref_name -> run ~repo_path ~sha ~mainline ~ref_name ()) $ Common.setup $ Common.repo_path $ sha_arg $ mainline_arg $ Common.target_ref_arg))
let cmd = let info = Cmd.info "drop" ~doc:"Remove a commit and re-parent its descendants (no checkout)." ~man: [ `S Manpage.s_description; `P "Remove $(b,SHA) from the chain reachable from $(b,--ref) by \ mapping its children directly to one of its parents."; `P "For a single-parent commit, descendants attach to the sole \ parent. For a merge, $(b,--mainline N) selects which 1-indexed \ parent to keep; the other sides of the merge become unreachable \ from $(b,--ref). Root commits cannot be dropped."; `S Manpage.s_examples; `P "Drop a specific commit from main:"; `Pre " $(tname) abc1234"; `P "Drop a merge commit, keeping the first-parent (mainline) side:"; `Pre " $(tname) --mainline 1 abc1234"; ] in Cmd.v info term