gitjgit

JGit: BundleWriter Error when including Refs


I am trying to create a git bundle of a repository using JGit's BundleWriter. I am attempting to include all Refs in my bundle like so:

Repository repo; // valid repo from elsewhere
BundleWriter bundleWriter = new BundleWriter(repo);

Map<String, Ref> refMap = repo.getAllRefs();
for (Ref ref:refMap.values()) {
    bundleWriter.include(ref);
}

JGit throws an exception for the symbolic HEAD ref, which refers to the default branch (refs/head/master)

java.lang.IllegalArgumentException: Invalid ref name: HEAD
at org.eclipse.jgit.transport.BundleWriter.include(BundleWriter.java:132)

If I exclude the HEAD symbolic ref the bundle is created fine but, when the bundle is cloned from, the missing HEAD reference causes the following git error:

warning: remote HEAD refers to nonexistent ref, unable to checkout.

I can manually checkout master to get things back to normal but it's not ideal behaviour as the bundle is being sent to other people who will expect it to work like any other git repository and include the HEAD reference pointing to the default branch.

Can anyone offer any advice or workarounds so that the default branch is set when the bundle is cloned?

Thanks


Solution

  • The bug has been reported to JGit in bug 446813 (by the OP I assume). It has already been fixed and will be released in the next JGit version (3.6).