我已经通过 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/