java - Jgit:Bare Repository 既没有工作树,也没有现有存储库的索引
问题描述
我有一个现有的存储库并试图指向现有的存储库并获得异常
Jgit:Bare Repository has neither a working tree, nor an index
使用现有存储库
public static Repository GetRepository(String destinationDirectory) throws IOException {
Repository existingRepo = new FileRepositoryBuilder().setGitDir(new File(destinationDirectory))
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
return existingRepo;
}
试图获取存储库的状态
public static void GitStatus(Repository repository) throws GitAPIException {
try (Git git = new Git(repository)) {
Status status = git.status().call();
System.out.println("Added: " + status.getAdded());
System.out.println("Changed: " + status.getChanged());
System.out.println("Conflicting: " + status.getConflicting());
System.out.println("ConflictingStageState: " + status.getConflictingStageState());
System.out.println("IgnoredNotInIndex: " + status.getIgnoredNotInIndex());
System.out.println("Missing: " + status.getMissing());
System.out.println("Modified: " + status.getModified());
System.out.println("Removed: " + status.getRemoved());
System.out.println("Untracked: " + status.getUntracked());
System.out.println("UntrackedFolders: " + status.getUntrackedFolders());
}
}
例外
Exception in thread "main" org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index
at org.eclipse.jgit.lib.Repository.getIndexFile(Repository.java:1147)
解决方案
推荐阅读
- python - 即使与 Python 客户端 Elasticsearch 的连接丢失,如何恢复流数据?
- java - 更新 recyclerview 中帖子的评论计数
- javascript - 使用 JS 向 Google Fit REST Api 添加会话和信息的问题
- git - Flutter 升级后 Flutter 找不到 git
- python - Python 无法识别 sum()。返回错误
- django - Django 中返回的多个对象
- python - Pandas:使用太多内存和条件滚动计数
- activemq - ActiveMQ ProtocolException 消息编码无效
- google-cloud-platform - 用于创建 Firestore 的 Terraform
- linux - 如何使用 Bluez L2CAP 发送更多字节?