我一直在尝试使用JGIT和JIMFS将一个小的git配置库克隆到内存中,代码示例如下:
FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
Path gitPath = Files.createDirectories(fs.getPath("/git"));
Git.cloneRepository().setURI(...).setBranch(...).setDirectory(gitPath.toFile())
.setCredentialsProvider(...).call()
但是由于JIMFS使用路径Path API(因为它不使用默认文件系统),而JGIT使用File API,因此JIMFS不支持toFile()调用:
@Override
public File toFile() {
// documented as unsupported for anything but the default file system
throw new UnsupportedOperationException();
}
我得到的是 UnsupportedOperationException
。有没有简单的方法让这个(或类似的)设置工作,而不必借助磁盘上的临时目录?