August Feng

libgit2

About

I'm having a little bit of fun with the libgit2sharp package and want to drive a running documentation of learnings.

APIs

Repository.Discover

The Repository.Discover api supports . as an argument. It eventually calls libgit2's git_repository_discover api.

If the API does not find a git directory, the returned value is null:

  open LibGit2Sharp

  let dir : string = Repository.Discover("/Users/august.feng")

  match dir with
  | null -> eprintf $"whoops."
  | s -> printfn $"{s}"

I've also learned of an elegant way to handle returned string values that are sometimes null to Option:

  open LibGit2Sharp

  let dir : string = Repository.Discover("/Users/august.feng")

  match dir |> Option.ofObj with
  | Some s -> printfn $"{s}"
  | None -> eprintf $"whoops."