繁体   English   中英

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

[英]Empty tag list for existing repository with JGit

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

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

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

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

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 然后我可以通过执行以下操作获取这些标签的地图

tagsMap = clonedRepository.getTags();

如果tagsMap变量的类型是Map <String, Ref> (请参阅参考资料 )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM