diff options
author | Marius Peter <marius.peter@tutanota.com> | 2025-02-02 18:56:47 +0100 |
---|---|---|
committer | Marius Peter <marius.peter@tutanota.com> | 2025-02-02 18:56:47 +0100 |
commit | e92e763e06d58a03224189d53044c4f5e1f907f0 (patch) | |
tree | aa0f3707d500fa883e6129d3f99da4b530e2011a /lib/git_helpers.ml | |
parent | aacec6588c3aebffda6c6221b02622576c85c407 (diff) |
Diffstat (limited to 'lib/git_helpers.ml')
-rw-r--r-- | lib/git_helpers.ml | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/git_helpers.ml b/lib/git_helpers.ml new file mode 100644 index 0000000..d973a88 --- /dev/null +++ b/lib/git_helpers.ml @@ -0,0 +1,20 @@ +open Lwt.Infix +open Git_unix + +let get_head_commit_hash repo_path = + let root = Fpath.v repo_path in + + (* 1. Open the Git repository *) + let%lwt repo = + Store.v root >>= function + | Ok repo -> Lwt.return repo + | Error _ -> Lwt.fail_with "Could not open the Git repository." + in + + (* 2. Resolve HEAD to get the latest commit hash *) + let%lwt commit_hash = + Git_unix.Store.Ref.resolve repo Git.Reference.master >>= function + | Ok hash -> Lwt.return hash + | Error _ -> Lwt.fail_with "Failed to resolve HEAD" + in + Lwt.return @@ (commit_hash |> Digestif.SHA1.to_hex) |