summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2017-07-24 09:01:55 -0700
committerShawn Pearce <spearce@spearce.org>2017-08-17 15:06:51 -0700
commit0aae64ce74d306f13bc6380beaf536dffd995c11 (patch)
treeb44e5566871208a0f0cd43b1c8181377feaaf691 /org.eclipse.jgit.test
parent195541dd30efc2c2a4f447038a3d3d085679693e (diff)
downloadjgit-0aae64ce74d306f13bc6380beaf536dffd995c11.tar.gz
jgit-0aae64ce74d306f13bc6380beaf536dffd995c11.zip
reftable: resolve symbolic references
resolve(Ref) helps callers recursively chase symbolic references and is a useful function when wrapping a Reftable inside a RefDatabase, as RefCursor does not resolve symbolic references during iteration. Change-Id: I1ba143f403773497972e225dc92c35ecb989e154
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java
index b53853b2e5..6809d7b2b2 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java
@@ -52,6 +52,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -240,6 +241,42 @@ public class ReftableTest {
}
@Test
+ public void resolveSymbolicRef() throws IOException {
+ Reftable t = read(write(
+ sym(HEAD, "refs/heads/tmp"),
+ sym("refs/heads/tmp", MASTER),
+ ref(MASTER, 1)));
+
+ Ref head = t.exactRef(HEAD);
+ assertNull(head.getObjectId());
+ assertEquals("refs/heads/tmp", head.getTarget().getName());
+
+ head = t.resolve(head);
+ assertNotNull(head);
+ assertEquals(id(1), head.getObjectId());
+
+ Ref master = t.exactRef(MASTER);
+ assertNotNull(master);
+ assertSame(master, t.resolve(master));
+ }
+
+ @Test
+ public void failDeepChainOfSymbolicRef() throws IOException {
+ Reftable t = read(write(
+ sym(HEAD, "refs/heads/1"),
+ sym("refs/heads/1", "refs/heads/2"),
+ sym("refs/heads/2", "refs/heads/3"),
+ sym("refs/heads/3", "refs/heads/4"),
+ sym("refs/heads/4", "refs/heads/5"),
+ sym("refs/heads/5", MASTER),
+ ref(MASTER, 1)));
+
+ Ref head = t.exactRef(HEAD);
+ assertNull(head.getObjectId());
+ assertNull(t.resolve(head));
+ }
+
+ @Test
public void oneDeletedRef() throws IOException {
String name = "refs/heads/gone";
Ref exp = newRef(name);