Chain several shell commands to get current commit of git folder

Let’s say I want to print the information of the latest commit hash of a git repo to a result file.

The following command would give a string of the latest commit for the current folder.

commit  = read(`git rev-parse HEAD`,String)[1:7]

However, I want the latest commit of a git repo that is located in REPO_PATH.

I thought maybe I can combine a cd REPO_PATH call with above command.

Any ideas how to do that?

Julia has a git library in the stdlibs:

julia> using LibGit2

help?> LibGit2.head
  LibGit2.head(repo::GitRepo) -> GitReference

  Return a GitReference to the current HEAD of repo.

  ────────────────────────────────────────────────────────

  head(pkg::AbstractString) -> String

  Return current HEAD GitHash of the pkg repo as a string.

Also take a look at this:

https://docs.julialang.org/en/stable/stdlib/LibGit2/

2 Likes