public class ArchiveCommand extends GitCommand<OutputStream>
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");
}
| Modifier and Type | Class and Description |
|---|---|
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).
|
repo| Constructor and Description |
|---|
ArchiveCommand(Repository repo) |
| Modifier and Type | Method and Description |
|---|---|
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.
|
checkCallable, getRepository, setCallablepublic ArchiveCommand(Repository repo)
repo - public static void registerFormat(String name, ArchiveCommand.Format<?> fmt)
name - name of a format (e.g., "tar" or "zip").fmt - archiver for that formatJGitInternalException - An archival format with that name was already registered.public static void unregisterFormat(String name)
name - name of format (e.g., "tar" or "zip").JGitInternalException - No such archival format was registered.public OutputStream call() throws GitAPIException
GitCommandcall in interface Callable<OutputStream>call in class GitCommand<OutputStream>GitAPIException - or subclass thereof when an error occurspublic ArchiveCommand setTree(ObjectId tree)
tree - the tag, commit, or tree object to produce an archive forpublic ArchiveCommand setPrefix(String prefix)
prefix - string prefixed to filenames in archive (e.g., "master/").
null means to not use any leading prefix.public ArchiveCommand setFilename(String filename)
setFormat(String).filename - intended filename for the archivepublic ArchiveCommand setOutputStream(OutputStream out)
out - the stream to which to write the archivepublic ArchiveCommand setFormat(String fmt)
fmt - archive format (e.g., "tar" or "zip").
null means to choose automatically based on
the archive filename.Copyright © 2014. All rights reserved.