summaryrefslogtreecommitdiff
path: root/lib/git_helpers.ml
blob: 0626d028559186c1efeca64825ba36429e7548c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
open Lwt.Infix

let get_head_commit_hash repo_path =
  let full_path = Filename.concat Config.git_directory repo_path in
  let%lwt store_result = Git_unix.Store.v @@ Fpath.v full_path in
  match store_result with
  | Error _ -> Lwt.return_error "Could not open the Git repository."
  | Ok store -> (
      Git_unix.Store.Ref.resolve store Git.Reference.head >|= function
      | Error _ -> Error ("Failed to resolve HEAD for repo " ^ repo_path)
      | Ok hash -> Ok (Git_unix.Store.Hash.to_hex hash))
Copyright 2019--2025 Marius PETER