diff options
author | Jonathan Nieder <jrn@google.com> | 2013-06-06 18:32:10 -0700 |
---|---|---|
committer | Jonathan Nieder <jrn@google.com> | 2013-06-06 18:39:07 -0700 |
commit | 1153a59e3820ebcba8b6871ae09304015c1d6f89 (patch) | |
tree | c164dcc37fd690cd61bda1fb8ffcf971145283d7 /org.eclipse.jgit.pgm | |
parent | 56cb2d925c93eadf03a551a2f40bbc9cb2b3241a (diff) | |
download | jgit-1153a59e3820ebcba8b6871ae09304015c1d6f89.tar.gz jgit-1153a59e3820ebcba8b6871ae09304015c1d6f89.zip |
Add support for "jgit archive --output=<filename>"
If the --format option is not given and the output filename is,
then infer the format from that filename. Otherwise match
"git archive" by defaulting to tar (this is a change from the
existing "jgit archive" default behavior, which was to default to
zip).
Change-Id: I5806bc48a403d05e4cfc3c180b82b33ad7cfae7f
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java index 0fc7afa6bb..7b88a94345 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java @@ -43,6 +43,11 @@ package org.eclipse.jgit.pgm; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.OutputStream; + +import org.eclipse.jgit.api.ArchiveCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.archive.ArchiveFormats; @@ -62,21 +67,39 @@ class Archive extends TextBuiltin { private ObjectId tree; @Option(name = "--format", metaVar = "metaVar_archiveFormat", usage = "usage_archiveFormat") - private String format = "zip"; + private String format; + + @Option(name = "--output", aliases = { "-o" }, metaVar = "metaVar_file", usage = "usage_archiveOutput") + private String output; @Override protected void run() throws Exception { if (tree == null) throw die(CLIText.get().treeIsRequired); + OutputStream stream = null; try { - new Git(db).archive() - .setTree(tree) - .setFormat(format) - .setOutputStream(outs) - .call(); + if (output != null) + stream = new FileOutputStream(output); + else + stream = outs; + + try { + ArchiveCommand cmd = new Git(db).archive() + .setTree(tree) + .setFormat(format) + .setOutputStream(stream); + if (output != null) + cmd.setFilename(output); + cmd.call(); } catch (GitAPIException e) { throw die(e.getMessage()); } + } catch (FileNotFoundException e) { + throw die(e.getMessage()); + } finally { + if (output != null && stream != null) + stream.close(); + } } } |