Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » ArchiveCommand - How to make an archive of a remote without cloning
ArchiveCommand - How to make an archive of a remote without cloning [message #1814087] Tue, 03 September 2019 11:42
Christoph Keiner is currently offline Christoph KeinerFriend
Messages: 1
Registered: September 2019
Junior Member
I recently started working with JGit and want to programmatically create an archive of a single folder of a certain branch of an arbitrary existing remote without cloning the whole repository. Using the normal command line git, this can be translated to the following command:
git archive --remote=<url/to/repo.git> --format=zip -o archive.zip <branch> <folder>


However, I failed building this command with JGit since the ArchiveCommand doesn't have an option to set a remote and requires a repository.
I also tried initializing a Git Repository with Git.init(), adding a remote and then calling JGit's archive, which also doesn't work. Sample code for this is below (although I'd rather not have to call Git.init).
So my question is: Is this actually possible? If not, are there reasons why this wasn't implemented?

public void archiveFromRemote(final String repositoryUrl, final String requestDirectory, final String archiveResultPath)
    {
        final Git git = Git.init().call();
        git.remoteAdd().setName("origin").setUri(new URIish(repositoryUrl));
        final ObjectId masterObjectId = git.getRepository().resolve("origin/master");

        final OutputStream archive = new FileOutputStream(archiveResultPath);

        final ZipArchiveFormat format = new ZipArchiveFormat();
        ArchiveCommand.registerFormat("zip", format);

        // No set remote available
        final ArchiveCommand archiveCmd = git.archive().setFormat("zip").setOutputStream(archive).setPaths(requestDirectory)
                                             .setTree(masterObjectId);
        try
        {
            archiveCmd.call();
        }
        catch (final GitAPIException e)
        {
            e.printStackTrace();
        }
        finally
        {
            git.close();
        }
    }
Previous Topic:EGit freezes Eclipse in 2019-06 release
Next Topic:Missing bundles in JGit P2 repository
Goto Forum:
  


Current Time: Thu Dec 05 21:50:11 GMT 2019

Powered by FUDForum. Page generated in 0.01914 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top