diff options
author | Marius Peter <marius.peter@tutanota.com> | 2025-03-01 19:19:30 +0100 |
---|---|---|
committer | Marius Peter <marius.peter@tutanota.com> | 2025-03-01 19:19:30 +0100 |
commit | 4946275b48bfc92ce4b420e36c6cf48694776bbc (patch) | |
tree | 0dad20f647c17f90d5ba583539a8a2f02d11e5ce /lib/git_helpers.ml | |
parent | e92e763e06d58a03224189d53044c4f5e1f907f0 (diff) |
Start work on Git "un"helper functions.
Worse is better. I'll revisit the OCaml Git package once I'm more
comfortable with OCaml overall.
Diffstat (limited to 'lib/git_helpers.ml')
-rw-r--r-- | lib/git_helpers.ml | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/lib/git_helpers.ml b/lib/git_helpers.ml index d973a88..0626d02 100644 --- a/lib/git_helpers.ml +++ b/lib/git_helpers.ml @@ -1,20 +1,11 @@ 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) + 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)) |