org.eclipse.jgit.api

## Class ArchiveCommand

- java.lang.Object
- - org.eclipse.jgit.api.GitCommand<OutputStream>
  - - org.eclipse.jgit.api.ArchiveCommand

All Implemented Interfaces:
  Callable<OutputStream>

    public class ArchiveCommand
    extends GitCommand<OutputStream>

Create an archive of files from a named tree.

Examples (`git` is a `Git` instance):

Create a tarball from HEAD:

     ArchiveCommand.registerFormat("tar", new TarFormat());
     try {
            git.archive()
                    .setTree(db.resolve("HEAD"))
                    .setOutputStream(out)
                    .call();
     } finally {
            ArchiveCommand.unregisterFormat("tar");
     }

Create a ZIP file from master:

     ArchiveCommand.registerFormat("zip", new ZipFormat());
     try {
            git.archive().
                    .setTree(db.resolve("master"))
                    .setFormat("zip")
                    .setOutputStream(out)
                    .call();
     } finally {
            ArchiveCommand.unregisterFormat("zip");
     }

Since:
  3.1
See Also:
  Git documentation about archive

### Nested Class Summary

Nested Classes
`static interface` `ArchiveCommand.Format<T extends Closeable>` Archival format.
`static class` `ArchiveCommand.UnsupportedFormatException` Signals an attempt to use an archival format that ArchiveCommand doesn't know about (for example due to a typo).

### Field Summary

### Fields inherited from class org.eclipse.jgit.api.GitCommand

`repo`

### Constructor Summary

Constructors
Constructor and Description
`ArchiveCommand(Repository repo)`

### Method Summary

Methods
`OutputStream` `call()` Executes the command
`static void` `registerFormat(String name, ArchiveCommand.Format<?> fmt)` Adds support for an additional archival format.
`ArchiveCommand` `setFilename(String filename)` Set the intended filename for the produced archive.
`ArchiveCommand` `setFormat(String fmt)`
`ArchiveCommand` `setOutputStream(OutputStream out)`
`ArchiveCommand` `setPrefix(String prefix)`
`ArchiveCommand` `setTree(ObjectId tree)`
`static void` `unregisterFormat(String name)` Removes support for an archival format so its Format can be garbage collected.

### Methods inherited from class org.eclipse.jgit.api.GitCommand

`checkCallable, getRepository, setCallable`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### ArchiveCommand

    public ArchiveCommand(Repository repo)

Parameters:
  `repo` -

### Method Detail

#### registerFormat

    public static void registerFormat(String name,
                      ArchiveCommand.Format<?> fmt)

Adds support for an additional archival format. To avoid unnecessary dependencies, ArchiveCommand does not have support for any formats built in; use this function to add them. OSGi plugins providing formats should call this function at bundle activation time.

Parameters:
  `name` - name of a format (e.g., "tar" or "zip").
  `fmt` - archiver for that format
Throws:
  `JGitInternalException` - An archival format with that name was already registered.

#### unregisterFormat

    public static void unregisterFormat(String name)

Removes support for an archival format so its Format can be garbage collected.

Parameters:
  `name` - name of format (e.g., "tar" or "zip").
Throws:
  `JGitInternalException` - No such archival format was registered.

#### call

    public OutputStream call()
                      throws GitAPIException

Description copied from class: `GitCommand`
Executes the command

Specified by:
  `call` in interface `Callable<OutputStream>`
Specified by:
  `call` in class `GitCommand<OutputStream>`
Returns:
  the stream to which the archive has been written
Throws:
  `GitAPIException` - or subclass thereof when an error occurs

#### setTree

    public ArchiveCommand setTree(ObjectId tree)

Parameters:
  `tree` - the tag, commit, or tree object to produce an archive for
Returns:
  this

#### setPrefix

    public ArchiveCommand setPrefix(String prefix)

Parameters:
  `prefix` - string prefixed to filenames in archive (e.g., "master/"). null means to not use any leading prefix.
Returns:
  this
Since:
  3.3

#### setFilename

    public ArchiveCommand setFilename(String filename)

Set the intended filename for the produced archive. Currently the only effect is to determine the default archive format when none is specified with `setFormat(String)`.

Parameters:
  `filename` - intended filename for the archive
Returns:
  this

#### setOutputStream

    public ArchiveCommand setOutputStream(OutputStream out)

Parameters:
  `out` - the stream to which to write the archive
Returns:
  this

#### setFormat

    public ArchiveCommand setFormat(String fmt)

Parameters:
  `fmt` - archive format (e.g., "tar" or "zip"). null means to choose automatically based on the archive filename.
Returns:
  this