无需使用 libgit2 克隆即可获取远程存储库的标签列表

Sil*_*lan 5 c++ git libgit2

使用这个 git 命令,我可以获得远程存储库的所有可用标签,而无需克隆它:

git ls-remote --tags https://github.com/blender/blender.git
Run Code Online (Sandbox Code Playgroud)

我想使用 来复制这个libgit2

我可以使用git_tag_listhttps://libgit2.org/libgit2/#HEAD/group/tag/git_tag_list)来获取标签列表,但它需要一个git_repository对象。我可以用来git_repository_open创建一个git_repository对象,但只有当存储库已被克隆并存在于磁盘本地时才有效。我似乎找不到任何git_repository使用远程存储库 URL 创建对象的方法。

libgit2 示例有该命令的实现ls-remote,因此它一定是可能的:

git ls-remote --tags https://github.com/blender/blender.git
Run Code Online (Sandbox Code Playgroud)

https://github.com/libgit2/libgit2/blob/ac0f2245510f6c75db1b1e7af7ca01c15dec26bc/examples/ls-remote.c

不幸的是这个命令还需要一个git_repository对象,所以我有点不知所措。目前如果不先克隆就不可能实现吗?

小智 0

可以使用lg2_ls_remote()fornullptr参数调用git_repository,无需克隆即可远程查找。