简体   繁体   中英

How to do a “git bundle create --all” in JGit?

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

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"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM