![](/img/trans.png)
[英]Is it possible to use JGit's in-memory repository to add one small file to a big Git repository without checking it out locally?
[英]Clone git repository in-memory
我一直在嘗試使用類似的東西使用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路徑 (因為它不使用默認的Filesystem),而JGIT使用File API ,JIMFS不實現toFile()調用:
@Override
public File toFile() {
// documented as unsupported for anything but the default file system
throw new UnsupportedOperationException();
}
所以我得到的是UnsupportedOperationException
。 是否有一種簡單的方法可以使這個(或類似的)設置工作而不需要求助於磁盤上的臨時目錄?
JGit提供了一個用於測試和實驗用途的InMemoryRepository
。 但即使是這個存儲庫后端也會將非裸存儲庫的工作目錄存儲在磁盤上。
除非JGit更改其FileRepository
實現以使用Paths API,否則我看不到使用Jimfs存儲存儲庫的方法。
某些命令允許指定WorkingTreeIterator
,理論上,它允許對備用存儲上的工作樹進行讀訪問。 但是,並非所有命令都支持此概念,目前也缺少寫訪問。
Yo可以將存儲庫克隆到內存中,並將文件按文件復制到自己的fs。 請參閱此處將文件讀入內存存儲庫內部的示例: https : //stackoverflow.com/a/54486558/449553
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.