Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone git repository in-memory

Tags:

java

git

jgit

jimfs

I've been trying to clone a tiny git configuration repository into memory using JGIT and JIMFS using something like

FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
Path gitPath = Files.createDirectories(fs.getPath("/git")); 
Git.cloneRepository().setURI(...).setBranch(...).setDirectory(gitPath.toFile())
                    .setCredentialsProvider(...).call()

But since JIMFS works with the path Path API (since it doesn't use the default Filesystem), while JGIT uses the File API, JIMFS doesn't implement to toFile() call:

@Override
public File toFile() {
    // documented as unsupported for anything but the default file system
    throw new UnsupportedOperationException();
}

So I get is this UnsupportedOperationException. Is there a simple way of getting this (or a similar) setup to work without resorting to a temp directory on the disk?

like image 988
Malt Avatar asked Oct 29 '22 04:10

Malt


1 Answers

JGit offers an InMemoryRepository for testing and experimental use. But even this repository backend would store the work directory of non-bare repositories on disk.

Unless JGit changes its FileRepository implementation to use the Paths API, I don't see a way to use Jimfs to store repositories.

Some commands allow specifying a WorkingTreeIterator, which in theory, would allow read-access to a working tree on an alternate storage. However, not all commands support this concept write-access is also currently missing.

like image 189
Rüdiger Herrmann Avatar answered Nov 09 '22 06:11

Rüdiger Herrmann