]> source.dussan.org Git - jgit.git/commitdiff
ArchiveCommand: Create prefix entry with commit time 78/98478/3
authorYasuhiro Takagi <ytakagi@bea.hi-ho.ne.jp>
Sat, 29 Apr 2017 11:35:10 +0000 (20:35 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Mon, 5 Jun 2017 23:35:46 +0000 (19:35 -0400)
The cgit archive command creates a prefix (root) directory entry
in the archive file. That entry's time is set to the commit time.

This patch makes jgit's behavior consistent with with cgit:

prefix: hoge/     -> creates prefix directory "hoge/" entry.
prefix: hoge////  -> creates prefix directory "hoge/" entry.
prefix: hoge/foo  -> does not create prefix directory entry, but for
                     each file/directory entry, prefix is added.

Change-Id: I2610e40ce37972c5f7456fdca6337e7fb07176e5
Signed-off-by: Yasuhiro Takagi <ytakagi@bea.hi-ho.ne.jp>
org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java
org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java

index 18c49ea286725e454d34b56cc189801f56e6ba61..6f32bfaa5283b19160376732ccdb20184a8af0d0 100644 (file)
@@ -348,7 +348,7 @@ public class ArchiveTest extends CLIRepositoryTestCase {
                commitBazAndFooSlashBar();
                byte[] result = CLIGitCommand.executeRaw(
                                "git archive --prefix=x/ --format=zip master", db).outBytes();
-               String[] expect = { "x/baz", "x/foo/", "x/foo/bar" };
+               String[] expect = { "x/", "x/baz", "x/foo/", "x/foo/bar" };
                String[] actual = listZipEntries(result);
 
                Arrays.sort(expect);
@@ -361,7 +361,7 @@ public class ArchiveTest extends CLIRepositoryTestCase {
                commitBazAndFooSlashBar();
                byte[] result = CLIGitCommand.executeRaw(
                                "git archive --prefix=x/ --format=tar master", db).outBytes();
-               String[] expect = { "x/baz", "x/foo/", "x/foo/bar" };
+               String[] expect = { "x/", "x/baz", "x/foo/", "x/foo/bar" };
                String[] actual = listTarEntries(result);
 
                Arrays.sort(expect);
@@ -380,7 +380,7 @@ public class ArchiveTest extends CLIRepositoryTestCase {
                commitFoo();
                byte[] result = CLIGitCommand.executeRaw(
                                "git archive --prefix=x// --format=zip master", db).outBytes();
-               String[] expect = { "x//foo" };
+               String[] expect = { "x/", "x//foo" };
                assertArrayEquals(expect, listZipEntries(result));
        }
 
@@ -389,7 +389,7 @@ public class ArchiveTest extends CLIRepositoryTestCase {
                commitFoo();
                byte[] result = CLIGitCommand.executeRaw(
                                "git archive --prefix=x// --format=tar master", db).outBytes();
-               String[] expect = { "x//foo" };
+               String[] expect = { "x/", "x//foo" };
                assertArrayEquals(expect, listTarEntries(result));
        }
 
index 0d18eb3d0730b475bb668e232eea1a13cde1ab87..7ea8e73b36842579e85b2b27839b6b0d8608cef3 100644 (file)
@@ -403,6 +403,12 @@ public class ArchiveCommand extends GitCommand<OutputStream> {
                                if (!paths.isEmpty())
                                        walk.setFilter(PathFilterGroup.createFromStrings(paths));
 
+                               // Put base directory into archive
+                               if (pfx.endsWith("/")) { //$NON-NLS-1$
+                                       fmt.putEntry(outa, tree, pfx.replaceAll("[/]+$", "/"), //$NON-NLS-1$ //$NON-NLS-2$
+                                                       FileMode.TREE, null);
+                               }
+
                                while (walk.next()) {
                                        String name = pfx + walk.getPathString();
                                        FileMode mode = walk.getFileMode(0);