diff options
author | Jonathan Nieder <jrn@google.com> | 2013-12-17 11:22:46 -0800 |
---|---|---|
committer | Jonathan Nieder <jrn@google.com> | 2013-12-17 11:22:46 -0800 |
commit | f2abbd0ea99aed638ca098e336f60f52bc923237 (patch) | |
tree | f35a719bc3f26b8c80a21135d443625608ad088b /org.eclipse.jgit.pgm.test | |
parent | aad7dee3ef492e9333581e8d6b2269dc091ea1d2 (diff) | |
download | jgit-f2abbd0ea99aed638ca098e336f60f52bc923237.tar.gz jgit-f2abbd0ea99aed638ca098e336f60f52bc923237.zip |
archive: Prepend a specified prefix to all entry filenames
Common practice when distributing tarballs is to prefix all entries
with a single directory name so when the tarball is extracted it all
falls neatly into a single directory. Add a setPrefix() method to
ArchiveCommand to support this.
Change-Id: I16b2832ef98c30977f6b77b646728b83d93c196f
Signed-off-by: Jonathan Nieder <jrn@google.com>
Diffstat (limited to 'org.eclipse.jgit.pgm.test')
-rw-r--r-- | org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java index 87137b475f..816094aef9 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java @@ -338,6 +338,99 @@ public class ArchiveTest extends CLIRepositoryTestCase { assertArrayEquals(expect, actual); } + private void commitBazAndFooSlashBar() throws Exception { + writeTrashFile("baz", "a file"); + writeTrashFile("foo/bar", "another file"); + git.add().addFilepattern("baz").call(); + git.add().addFilepattern("foo").call(); + git.commit().setMessage("sample commit").call(); + } + + @Test + public void testArchivePrefixOption() throws Exception { + commitBazAndFooSlashBar(); + byte[] result = CLIGitCommand.rawExecute( + "git archive --prefix=x/ --format=zip master", db); + String[] expect = { "x/baz", "x/foo/bar" }; + String[] actual = listZipEntries(result); + + Arrays.sort(expect); + Arrays.sort(actual); + assertArrayEquals(expect, actual); + } + + @Test + public void testTarPrefixOption() throws Exception { + commitBazAndFooSlashBar(); + byte[] result = CLIGitCommand.rawExecute( + "git archive --prefix=x/ --format=tar master", db); + String[] expect = { "x/baz", "x/foo/bar" }; + String[] actual = listTarEntries(result); + + Arrays.sort(expect); + Arrays.sort(actual); + assertArrayEquals(expect, actual); + } + + private void commitFoo() throws Exception { + writeTrashFile("foo", "a file"); + git.add().addFilepattern("foo").call(); + git.commit().setMessage("boring commit").call(); + } + + @Test + public void testPrefixDoesNotNormalizeDoubleSlash() throws Exception { + commitFoo(); + byte[] result = CLIGitCommand.rawExecute( + "git archive --prefix=x// --format=zip master", db); + String[] expect = { "x//foo" }; + assertArrayEquals(expect, listZipEntries(result)); + } + + @Test + public void testPrefixDoesNotNormalizeDoubleSlashInTar() throws Exception { + commitFoo(); + final byte[] result = CLIGitCommand.rawExecute( // + "git archive --prefix=x// --format=tar master", db); + String[] expect = { "x//foo" }; + assertArrayEquals(expect, listTarEntries(result)); + } + + /** + * The prefix passed to "git archive" need not end with '/'. + * In practice it is not very common to have a nonempty prefix + * that does not name a directory (and hence end with /), but + * since git has historically supported other prefixes, we do, + * too. + * + * @throws Exception + */ + @Test + public void testPrefixWithoutTrailingSlash() throws Exception { + commitBazAndFooSlashBar(); + byte[] result = CLIGitCommand.rawExecute( + "git archive --prefix=my- --format=zip master", db); + String[] expect = { "my-baz", "my-foo/bar" }; + String[] actual = listZipEntries(result); + + Arrays.sort(expect); + Arrays.sort(actual); + assertArrayEquals(expect, actual); + } + + @Test + public void testTarPrefixWithoutTrailingSlash() throws Exception { + commitBazAndFooSlashBar(); + final byte[] result = CLIGitCommand.rawExecute( // + "git archive --prefix=my- --format=tar master", db); + String[] expect = { "my-baz", "my-foo/bar" }; + 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"); |