aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java')
-rw-r--r--org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java26
1 files changed, 22 insertions, 4 deletions
diff --git a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java
index 23f4beda14..7e1c9cc907 100644
--- a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java
+++ b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java
@@ -47,12 +47,14 @@ import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.text.MessageFormat;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.archivers.tar.TarConstants;
import org.eclipse.jgit.api.ArchiveCommand;
+import org.eclipse.jgit.archive.internal.ArchiveText;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectLoader;
@@ -83,13 +85,29 @@ public class TarFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
return;
}
+ // TarArchiveEntry detects directories by checking
+ // for '/' at the end of the filename.
+ if (path.endsWith("/") && mode != FileMode.TREE)
+ throw new IllegalArgumentException(MessageFormat.format(
+ ArchiveText.get().pathDoesNotMatchMode, path, mode));
+ if (!path.endsWith("/") && mode == FileMode.TREE)
+ path = path + "/";
+
final TarArchiveEntry entry = new TarArchiveEntry(path);
- if (mode == FileMode.REGULAR_FILE ||
- mode == FileMode.EXECUTABLE_FILE) {
+ if (mode == FileMode.TREE) {
+ out.putArchiveEntry(entry);
+ out.closeArchiveEntry();
+ return;
+ }
+
+ if (mode == FileMode.REGULAR_FILE) {
+ // ok
+ } else if (mode == FileMode.EXECUTABLE_FILE) {
entry.setMode(mode.getBits());
} else {
- // TODO(jrn): Let the caller know the tree contained
- // an entry with unsupported mode (e.g., a submodule).
+ // Unsupported mode (e.g., GITLINK).
+ throw new IllegalArgumentException(MessageFormat.format(
+ ArchiveText.get().unsupportedMode, mode));
}
entry.setSize(loader.getSize());
out.putArchiveEntry(entry);