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 <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)
        catch (final GitAPIException e)
Previous Topic:EGit freezes Eclipse in 2019-06 release
Next Topic:Missing bundles in JGit P2 repository
Goto Forum:

Current Time: Wed May 25 04:16:52 GMT 2022

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

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

Back to the top