summaryrefslogtreecommitdiff
path: root/lib/git_helpers.ml
blob: 07b0d049f703ed92596acb0f7a529134a7f3562e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
type commit_info = {
  hash : string;
  message : string option;
  author : string;
  date : string;
}

let full_path path = Filename.concat Config.git_directory path

let store repo_path =
  let path = Fpath.v @@ full_path repo_path in
  Git_unix.Store.v ~dotgit:path path

let latest_commits repo_path ~count =
  let open Lwt_result.Syntax in
  let* store_result = store repo_path in
  let* commits = Git.Commit.Make in
  commits

let all_branches repo_path =
  let cmd =
    Printf.sprintf "git -C %s branch --format=%%(refname:short)"
    @@ full_path repo_path
  in
  Lwt.catch
    (fun () ->
      let%lwt output = Lwt_process.pread ("", [| "sh"; "-c"; cmd |]) in
      let branches =
        String.split_on_char '\n' output
        |> List.filter (fun s -> String.trim s <> "")
      in
      Lwt.return_ok branches)
    (fun exn -> Lwt.return_error (Printexc.to_string exn))
Copyright 2019--2025 Marius PETER