diff options
author | Jonathan Nieder <jrn@google.com> | 2017-04-12 21:12:12 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2017-04-12 21:12:15 -0400 |
commit | e730fcce776b795692bbae086f0333bb4ae38a6c (patch) | |
tree | 7da59509d440f6366714f4f3f8c32d03de3960b3 /org.eclipse.jgit.test | |
parent | 56a1cced74b7baf03c0db91af9b9f2e9f278a5ab (diff) | |
parent | c9c9e672e599f224417a8a9287ddae3ab7a5a079 (diff) | |
download | jgit-e730fcce776b795692bbae086f0333bb4ae38a6c.tar.gz jgit-e730fcce776b795692bbae086f0333bb4ae38a6c.zip |
Merge "BundleWriter: Allow constructing from only an ObjectReader"
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java index a83a993330..658b971acb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java @@ -45,7 +45,10 @@ package org.eclipse.jgit.transport; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -59,10 +62,16 @@ import java.util.Collections; import java.util.Set; import org.eclipse.jgit.errors.MissingBundlePrerequisiteException; +import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.TransportException; +import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription; +import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository; +import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.ObjectInserter; +import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; @@ -161,6 +170,39 @@ public class BundleWriterTest extends SampleDataRepositoryTestCase { assertTrue(caught); } + @Test + public void testCustomObjectReader() throws Exception { + String refName = "refs/heads/blob"; + String data = "unflushed data"; + ObjectId id; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + try (Repository repo = new InMemoryRepository( + new DfsRepositoryDescription("repo")); + ObjectInserter ins = repo.newObjectInserter(); + ObjectReader or = ins.newReader()) { + id = ins.insert(OBJ_BLOB, Constants.encode(data)); + BundleWriter bw = new BundleWriter(or); + bw.include(refName, id); + bw.writeBundle(NullProgressMonitor.INSTANCE, out); + assertNull(repo.exactRef(refName)); + try { + repo.open(id, OBJ_BLOB); + fail("We should not be able to open the unflushed blob"); + } catch (MissingObjectException e) { + // Expected. + } + } + + try (Repository repo = new InMemoryRepository( + new DfsRepositoryDescription("copy"))) { + fetchFromBundle(repo, out.toByteArray()); + Ref ref = repo.exactRef(refName); + assertNotNull(ref); + assertEquals(id, ref.getObjectId()); + assertEquals(data, new String(repo.open(id, OBJ_BLOB).getBytes(), UTF_8)); + } + } + private static FetchResult fetchFromBundle(final Repository newRepo, final byte[] bundle) throws URISyntaxException, NotSupportedException, TransportException { |