How to draw git output using in-memory database in JGit?

I want to create a Java program that

  • connects to a specific Git repository,
  • adds text to the file,
  • fixes and
  • causes changes to this repository.

Ideally, all this should happen in memory.

I use JGit to interact 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(); 

pull.call() 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 get the contents of a repository to a JGit repository in memory?

+6
source share
1 answer

To add a file, you will need a non-bare repository (one that has a working directory. This mailing list states that

In some cases, porcelain commands suggest a file base, especially when it comes to the working tree. You can insert into the repository in memory if you do the work yourself, but porcelain commands do not work that way.

While you could get by with procelain commands , I also recommend (for example, @Wayne comment above) to clone to a temporary repository, join the file, click, and then delete the repository.

+3
source

Source: https://habr.com/ru/post/985873/


All Articles