Something went wrong. Try again.
Git format in pure OCaml
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263(* 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 reword." in Arg.(required & pos 0 (some string) None & info [] ~docv:"SHA" ~doc)
let message_arg = let doc = "New commit message. Repeat $(b,-m) to add paragraphs: each value becomes \ its own paragraph, separated by a blank line, as with $(b,git commit)." in Arg.(non_empty & opt_all string [] & info [ "m"; "message" ] ~docv:"MSG" ~doc)
let run ~repo_path ~sha ~message ~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.reword_commit repo ~commit ~message ~ref_name |> Common.report_rewrite_result)
let term = Term.( ret (const (fun () repo_path sha messages ref_name -> let message = String.concat "\n\n" messages in run ~repo_path ~sha ~message ~ref_name ()) $ Common.setup $ Common.repo_path $ sha_arg $ message_arg $ Common.target_ref_arg))
let cmd = let info = Cmd.info "reword" ~doc:"Change a commit's message in place (no checkout)." ~man: [ `S Manpage.s_description; `P "Replace the message of $(b,SHA) with the supplied $(b,--message), \ then re-parent every descendant on $(b,--ref). The working tree, \ index, and HEAD are not touched."; `P "Errors out if $(b,SHA) is not reachable from $(b,--ref) or if \ $(b,--ref) does not exist."; `S Manpage.s_examples; `P "Reword the most recent commit on main:"; `Pre " $(tname) $$(git rev-parse main) -m \"better message\""; ] in Cmd.v info term