Does JGit API have all Git commands

一个人想着一个人 提交于 2019-12-23 02:32:40

问题


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 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.).



来源:https://stackoverflow.com/questions/27225273/does-jgit-api-have-all-git-commands

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!