LibGit2 question

The library LibGit2 is part of Julia, I think.

How can I achieve the aquivalent of:

git diff --name-only --cached

using LibGit2?

I tried:

    repo = LibGit2.GitRepo(".")
    LibGit2.diff_files(repo, "main", "origin/main")

which does not work (it returns an empty AbstractString).

Any idea?

I just want to get a list of staged files.

If you only want to use LibGit2 in order not to rely on an external git being available on the system, you might prefer to use the Git package instead:

using Git
git = Git.git()
staged_files = readlines(`$git diff --name-only --cached`)

Whether it can be done with LibGit2 I have no idea though.

2 Likes