java - 使用 JGit 的现有存储库的空标签列表

标签 java git jgit

我已经通过 JGit 的 CloneCommand 克隆了一个 git 存储库,现在我正在尝试获取我要 checkout 的标签列表。但是当我执行

Git git = Git.wrap(clonedRepository);
List<Ref> tagsList = git.tagList().call();

然后是tagsList.size(),它返回0。克隆的存储库设置为 true 来克隆所有分支,并且它不是裸克隆的。当我检查路径 refs/tags/ 中的 .git 文件夹时,我找到了需要 checkout 的所有标签。

在这里,我添加了有关如何克隆远程存储库的更多详细信息:

File path = new File(localPath);
path.delete();

FileRepositoryBuilder builder = new FileRepositoryBuilder();
clonedRepository = builder.setGitDir(path).readEnvironment().findGitDir().build();

CloneCommand clone = Git.cloneRepository();

clone.setBare(false);
clone.setCloneAllBranches(true);
clone.setDirectory(path).setURI(remotePath);
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password));
clone.call();

其中 localPath = "./target/ClonedRepository"remotePath 是我的 git 地址 (http)。

最佳答案

clonedRepository没有指向我想要的存储库路径(本地克隆的路径)。以下代码行解决了这个问题:

Git git = clone.call();
clonedRepository = git.getRepository();

从这个意义上来说,clonedRepository指向.git包含项目的所有标签。然后我可以通过执行来获取这些标签的 map

tagsMap = clonedRepository.getTags();

其中 tagsMap 的类型变量是 Map <String, Ref> (参见reference)。

关于java - 使用 JGit 的现有存储库的空标签列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33783439/

相关文章:

Java Used Heap RAM 使用高峰,我该如何避免?

java - 原因: no instance(s) of type variable(s) T exist so that void conforms to using mockito

git - 如何从别人的 repo 中 pull 出远程分支

java - 我如何使用 JGit 进行 pull 或获取?

git - 对 JGIT 的 gpg 签名支持

java - 从本地存储库中删除文件后,JGit 没有删除我的文件

java - 在 JPA 中加入命名查询

java - 在 Spring 中读取 JAAS 身份验证提供程序的配置文件时出错

Git克隆ssh,用户名、路径和不同驱动器中带有空格

mysql - 限制 : 1 difference in schema. rb bool 字段