ArchiveCommand: Create prefix entry with commit time
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>
This commit is contained in:
parent
6b1e3c58b1
commit
a66e60a986
|
@ -348,7 +348,7 @@ public void testArchivePrefixOption() throws Exception {
|
||||||
commitBazAndFooSlashBar();
|
commitBazAndFooSlashBar();
|
||||||
byte[] result = CLIGitCommand.executeRaw(
|
byte[] result = CLIGitCommand.executeRaw(
|
||||||
"git archive --prefix=x/ --format=zip master", db).outBytes();
|
"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);
|
String[] actual = listZipEntries(result);
|
||||||
|
|
||||||
Arrays.sort(expect);
|
Arrays.sort(expect);
|
||||||
|
@ -361,7 +361,7 @@ public void testTarPrefixOption() throws Exception {
|
||||||
commitBazAndFooSlashBar();
|
commitBazAndFooSlashBar();
|
||||||
byte[] result = CLIGitCommand.executeRaw(
|
byte[] result = CLIGitCommand.executeRaw(
|
||||||
"git archive --prefix=x/ --format=tar master", db).outBytes();
|
"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);
|
String[] actual = listTarEntries(result);
|
||||||
|
|
||||||
Arrays.sort(expect);
|
Arrays.sort(expect);
|
||||||
|
@ -380,7 +380,7 @@ public void testPrefixDoesNotNormalizeDoubleSlash() throws Exception {
|
||||||
commitFoo();
|
commitFoo();
|
||||||
byte[] result = CLIGitCommand.executeRaw(
|
byte[] result = CLIGitCommand.executeRaw(
|
||||||
"git archive --prefix=x// --format=zip master", db).outBytes();
|
"git archive --prefix=x// --format=zip master", db).outBytes();
|
||||||
String[] expect = { "x//foo" };
|
String[] expect = { "x/", "x//foo" };
|
||||||
assertArrayEquals(expect, listZipEntries(result));
|
assertArrayEquals(expect, listZipEntries(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ public void testPrefixDoesNotNormalizeDoubleSlashInTar() throws Exception {
|
||||||
commitFoo();
|
commitFoo();
|
||||||
byte[] result = CLIGitCommand.executeRaw(
|
byte[] result = CLIGitCommand.executeRaw(
|
||||||
"git archive --prefix=x// --format=tar master", db).outBytes();
|
"git archive --prefix=x// --format=tar master", db).outBytes();
|
||||||
String[] expect = { "x//foo" };
|
String[] expect = { "x/", "x//foo" };
|
||||||
assertArrayEquals(expect, listTarEntries(result));
|
assertArrayEquals(expect, listTarEntries(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -403,6 +403,12 @@ private <T extends Closeable> OutputStream writeArchive(Format<T> fmt) {
|
||||||
if (!paths.isEmpty())
|
if (!paths.isEmpty())
|
||||||
walk.setFilter(PathFilterGroup.createFromStrings(paths));
|
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()) {
|
while (walk.next()) {
|
||||||
String name = pfx + walk.getPathString();
|
String name = pfx + walk.getPathString();
|
||||||
FileMode mode = walk.getFileMode(0);
|
FileMode mode = walk.getFileMode(0);
|
||||||
|
|
Loading…
Reference in New Issue