I want to create a Java program, which
Ideally, all of this should happen in the memory.
I'm using JGit for interaction with Git:
InMemoryRepository repo = new InMemoryRepository(new DfsRepositoryDescription());
Git git = new Git(repo);
git.init().call();
PullCommand pull = git.pull();
StoredConfig config = git.getRepository().getConfig();
config.setString("remote", "origin", "url", "https://XXX");
config.save();
PullResult result = pull.call();
The pull.call()
results in the following exception:
org.eclipse.jgit.api.errors.NoHeadException: Pull on repository without HEAD currently not supported
at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:191)
How can I retrieve the contents of a repository into an in-memory JGit repository?
To append a file you would need a non-bare repository (one that has a work directory. This mailing list post states, that
The porcelain commands assume a File basis in some cases, particularly when it comes to the working tree. You can perform inserts into an in-memory repository if you do the work yourself, but the porcelain commands do not work in that way.
While you could do without the procelain commands, I also recommend (like @Wayne commented above) to clone into a temporary repository, append to the file, push and then delete the repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With