5

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?

Malt
  • 28,965
  • 9
  • 65
  • 105

2 Answers2

2

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.

RĂ¼diger Herrmann
  • 20,512
  • 11
  • 62
  • 79
0

You can clone repository into memory and copy it file by file to own fs. See example of reading files into internal in memory repo here: https://stackoverflow.com/a/54486558/449553

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
msangel
  • 9,895
  • 3
  • 50
  • 69