Browse Source

Merge "archive: Use an empty directory for submodules"

stable-3.3
Dave Borowitz 11 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
b0d9c57f35
  1. 40
      org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java
  2. 13
      org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java

40
org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java

@ -432,6 +432,46 @@ public class ArchiveTest extends CLIRepositoryTestCase {
assertArrayEquals(expect, actual);
}
@Test
public void testArchiveIncludesSubmoduleDirectory() throws Exception {
writeTrashFile("a", "a file with content!");
writeTrashFile("c", "after submodule");
git.add().addFilepattern("a").call();
git.add().addFilepattern("c").call();
git.commit().setMessage("initial commit").call();
git.submoduleAdd().setURI("./.").setPath("b").call().close();
git.commit().setMessage("add submodule").call();
final byte[] result = CLIGitCommand.rawExecute( //
"git archive --format=zip master", db);
String[] expect = { ".gitmodules", "a", "b/", "c" };
String[] actual = listZipEntries(result);
Arrays.sort(expect);
Arrays.sort(actual);
assertArrayEquals(expect, actual);
}
@Test
public void testTarIncludesSubmoduleDirectory() throws Exception {
writeTrashFile("a", "a file with content!");
writeTrashFile("c", "after submodule");
git.add().addFilepattern("a").call();
git.add().addFilepattern("c").call();
git.commit().setMessage("initial commit").call();
git.submoduleAdd().setURI("./.").setPath("b").call().close();
git.commit().setMessage("add submodule").call();
final byte[] result = CLIGitCommand.rawExecute( //
"git archive --format=tar master", db);
String[] expect = { ".gitmodules", "a", "b/", "c" };
String[] actual = listTarEntries(result);
Arrays.sort(expect);
Arrays.sort(actual);
assertArrayEquals(expect, actual);
}
@Test
public void testArchivePreservesMode() throws Exception {
writeTrashFile("plain", "a file with content");

13
org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java

@ -279,11 +279,18 @@ public class ArchiveCommand extends GitCommand<OutputStream> {
walk.reset(rw.parseTree(tree));
while (walk.next()) {
final String name = pfx + walk.getPathString();
final FileMode mode = walk.getFileMode(0);
FileMode mode = walk.getFileMode(0);
if (walk.isSubtree()) {
fmt.putEntry(outa, name + "/", mode, null);
if (walk.isSubtree())
walk.enterSubtree();
if (mode == FileMode.GITLINK)
// TODO(jrn): Take a callback to recurse
// into submodules.
mode = FileMode.TREE;
if (mode == FileMode.TREE) {
fmt.putEntry(outa, name + "/", mode, null);
continue;
}
walk.getObjectId(idBuf, 0);

Loading…
Cancel
Save