Does JGit API have all Git commands

630 views Asked by At

I am trying to port a shell script to Java which contains a few Git commands which I have mostly managed to find in the JGit API. I have not, however, managed to find the remote or am commands, is this because the don't exist or I am just looking in the wrong place for them. If they don't exist is there another way to use them?

1

There are 1 answers

0
RĂ¼diger Herrmann On BEST ANSWER

There is no ready-to run counterpart for git remote and am in JGit, but it should be possible to implement (a subset of) them with reasonable effort.

Those sub-commands of git remote that query or manipulate the config file can be emulated by directly accessing the repository configuration through Repository.getConfig().

To clean stale remote-tracking branches like git remote prune does, you can use LsRemoteCommand to obtain a list of existing remote branches and remove remotes from the local configuration that do not match that list.

Replacing git am might be a little more effort. There is an ApplyCommand to apply a patch from a given input stream as well as the low-level Patch class to parse diffs. What would be left is to parse the mailbox files and produce a commit from the contained diffs and meta-data (message, author, etc.).