[英]List branches of a git remote repo without cloning it
I was wondering hows it would be possible to list all the branches of a remote Git repo with jgit but without cloning it. 我想知道怎么可能用jgit列出远程Git仓库的所有分支但没有克隆它。
While going through the jgit's javadoc, I found the ListBranchCommand but that only seem to work with an already opened Repository object. 在浏览jgit的javadoc时,我发现了ListBranchCommand,但它似乎只适用于已经打开的Repository对象。 But I was not able to find how to create a Repository object over HTTP without cloning it in local.
但我无法找到如何通过HTTP创建Repository对象而不在本地克隆它。
Is it possible ? 可能吗 ? Thanks
谢谢
There is the LsRemoteCommand
to list the branches of a remote repository. LsRemoteCommand
用于列出远程存储库的分支。 To obtain the command, use either 要获取该命令,请使用其中一个
Git.wrap( repo ).lsRemote()
or 要么
Git.lsRemoteRepository()
The statically created LsRemoteCommand
has its limitations. 静态创建的
LsRemoteCommand
有其局限性。 For certain transport protocols, a local repository is necessary to obtain configuration settings. 对于某些传输协议,需要本地存储库来获取配置设置。 Therefore I usually create an empty temporary local repository with
Git.init()
and then use the first approach. 因此,我通常使用
Git.init()
创建一个空的临时本地存储库,然后使用第一种方法。
If you want to avoid creating the extra repository, you can test with Transport.open()
if it succeeds without a repository. 如果要避免创建额外的存储库,可以使用
Transport.open()
进行测试,如果它没有存储库则成功。 It throws a NotSupportedException
otherwise. 否则会抛出
NotSupportedException
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.