2

Is it possible to bundle a repository using JGit?

I'm trying to do the equivalent of this git command:

git --git-dir=path/to/my/local/repo bundle create path/to/backup.bundle --all
Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154
Pado
  • 1,497
  • 16
  • 28

1 Answers1

2

Looking at the documentation, I'd say yes:

public class BundleWriter
extends Object

Creates a Git bundle file, for sneaker-net transport to another system.

Here's an (untested) example:

Repository repo = new FileRepositoryBuilder()
    .setGitDir(new File("path/to/my/local/repo/.git"))
    .build();
BundleWriter bundle = new BundleWriter(repo);

for (Ref ref : repo.getRefDatabase().getRefs()) {
    bundle.include(ref);
}

bundle.writeBundle(
    new NullProgressMonitor(),
    new FileOutputStream("path/to/backup.bundle"));
Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154
  • Works like a charm for me, thanks. The only problem I encountered is that `NullProgressMonitor()` is not available for my specific API version (5.8.1.202007141445-r). I used `new EmptyProgressMonitor() {}` instead – Pado Aug 24 '20 at 11:43