Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java57
1 files changed, 56 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java
index 6e98541603..2a13022326 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java
@@ -48,6 +48,14 @@ import static org.eclipse.jgit.lib.Constants.R_HEADS;
import static org.eclipse.jgit.lib.Constants.R_TAGS;
import static org.eclipse.jgit.lib.Ref.Storage.LOOSE;
import static org.eclipse.jgit.lib.Ref.Storage.NEW;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
@@ -61,6 +69,8 @@ import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTag;
+import org.junit.Before;
+import org.junit.Test;
public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
private Repository diskRepo;
@@ -75,7 +85,8 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
private RevTag v1_0;
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
super.setUp();
diskRepo = createBareRepository();
@@ -88,6 +99,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
repo.getRevWalk().parseBody(v1_0);
}
+ @Test
public void testCreate() throws IOException {
// setUp above created the directory. We just have to test it.
File d = diskRepo.getDirectory();
@@ -111,6 +123,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals("ref: refs/heads/master\n", read(new File(d, HEAD)));
}
+ @Test
public void testGetRefs_EmptyDatabase() throws IOException {
Map<String, Ref> all;
@@ -124,6 +137,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertTrue("no references", all.isEmpty());
}
+ @Test
public void testGetRefs_HeadOnOneBranch() throws IOException {
Map<String, Ref> all;
Ref head, master;
@@ -149,6 +163,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(A, master.getObjectId());
}
+ @Test
public void testGetRefs_DeatchedHead1() throws IOException {
Map<String, Ref> all;
Ref head;
@@ -168,6 +183,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(A, head.getObjectId());
}
+ @Test
public void testGetRefs_DeatchedHead2() throws IOException {
Map<String, Ref> all;
Ref head, master;
@@ -193,6 +209,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(B, master.getObjectId());
}
+ @Test
public void testGetRefs_DeeplyNestedBranch() throws IOException {
String name = "refs/heads/a/b/c/d/e/f/g/h/i/j/k";
Map<String, Ref> all;
@@ -210,6 +227,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(A, r.getObjectId());
}
+ @Test
public void testGetRefs_HeadBranchNotBorn() throws IOException {
Map<String, Ref> all;
Ref a, b;
@@ -231,6 +249,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals("refs/heads/B", b.getName());
}
+ @Test
public void testGetRefs_LooseOverridesPacked() throws IOException {
Map<String, Ref> heads;
Ref a;
@@ -246,6 +265,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(B, a.getObjectId());
}
+ @Test
public void testGetRefs_IgnoresGarbageRef1() throws IOException {
Map<String, Ref> heads;
Ref a;
@@ -261,6 +281,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(A, a.getObjectId());
}
+ @Test
public void testGetRefs_IgnoresGarbageRef2() throws IOException {
Map<String, Ref> heads;
Ref a;
@@ -276,6 +297,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(A, a.getObjectId());
}
+ @Test
public void testGetRefs_IgnoresGarbageRef3() throws IOException {
Map<String, Ref> heads;
Ref a;
@@ -291,6 +313,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(A, a.getObjectId());
}
+ @Test
public void testGetRefs_IgnoresGarbageRef4() throws IOException {
Map<String, Ref> heads;
Ref a, b, c;
@@ -323,6 +346,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(A, c.getObjectId());
}
+ @Test
public void testGetRefs_InvalidName() throws IOException {
writeLooseRef("refs/heads/A", A);
@@ -331,6 +355,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertTrue("empty objects/", refdir.getRefs("objects/").isEmpty());
}
+ @Test
public void testGetRefs_HeadsOnly_AllLoose() throws IOException {
Map<String, Ref> heads;
Ref a, b;
@@ -352,6 +377,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(B, b.getObjectId());
}
+ @Test
public void testGetRefs_HeadsOnly_AllPacked1() throws IOException {
Map<String, Ref> heads;
Ref a;
@@ -368,6 +394,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(A, a.getObjectId());
}
+ @Test
public void testGetRefs_HeadsOnly_SymrefToPacked() throws IOException {
Map<String, Ref> heads;
Ref master, other;
@@ -389,6 +416,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertSame(master, other.getTarget());
}
+ @Test
public void testGetRefs_HeadsOnly_Mixed() throws IOException {
Map<String, Ref> heads;
Ref a, b;
@@ -410,6 +438,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(B, b.getObjectId());
}
+ @Test
public void testGetRefs_TagsOnly_AllLoose() throws IOException {
Map<String, Ref> tags;
Ref a;
@@ -426,6 +455,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(v1_0, a.getObjectId());
}
+ @Test
public void testGetRefs_TagsOnly_AllPacked() throws IOException {
Map<String, Ref> tags;
Ref a;
@@ -442,6 +472,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(v1_0, a.getObjectId());
}
+ @Test
public void testGetRefs_DiscoversNewLoose1() throws IOException {
Map<String, Ref> orig, next;
Ref orig_r, next_r;
@@ -470,6 +501,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(B, next_r.getObjectId());
}
+ @Test
public void testGetRefs_DiscoversNewLoose2() throws IOException {
Map<String, Ref> orig, next, news;
@@ -493,6 +525,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertTrue(news.containsKey("B"));
}
+ @Test
public void testGetRefs_DiscoversModifiedLoose() throws IOException {
Map<String, Ref> all;
@@ -506,6 +539,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(B, all.get(HEAD).getObjectId());
}
+ @Test
public void testGetRef_DiscoversModifiedLoose() throws IOException {
Map<String, Ref> all;
@@ -520,6 +554,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(B, master.getObjectId());
}
+ @Test
public void testGetRefs_DiscoversDeletedLoose1() throws IOException {
Map<String, Ref> orig, next;
Ref orig_r, next_r;
@@ -549,6 +584,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(B, orig_r.getObjectId());
}
+ @Test
public void testGetRef_DiscoversDeletedLoose() throws IOException {
Map<String, Ref> all;
@@ -561,6 +597,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertTrue(refdir.getRefs(RefDatabase.ALL).isEmpty());
}
+ @Test
public void testGetRefs_DiscoversDeletedLoose2() throws IOException {
Map<String, Ref> orig, next;
@@ -578,6 +615,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertFalse(next.containsKey("refs/heads/pu"));
}
+ @Test
public void testGetRefs_DiscoversDeletedLoose3() throws IOException {
Map<String, Ref> orig, next;
@@ -600,6 +638,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertFalse(next.containsKey("refs/heads/next"));
}
+ @Test
public void testGetRefs_DiscoversDeletedLoose4() throws IOException {
Map<String, Ref> orig, next;
Ref orig_r, next_r;
@@ -625,6 +664,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertSame("uses cached instance", orig_r, next_r);
}
+ @Test
public void testGetRefs_DiscoversDeletedLoose5() throws IOException {
Map<String, Ref> orig, next;
@@ -645,6 +685,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertTrue(next.containsKey("refs/tags/v1.0"));
}
+ @Test
public void testGetRefs_SkipsLockFiles() throws IOException {
Map<String, Ref> all;
@@ -659,6 +700,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertFalse(all.containsKey("refs/heads/pu.lock"));
}
+ @Test
public void testGetRefs_CycleInSymbolicRef() throws IOException {
Map<String, Ref> all;
Ref r;
@@ -711,6 +753,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertNull("mising 1 due to cycle", r);
}
+ @Test
public void testGetRefs_PackedNotPeeled_Sorted() throws IOException {
Map<String, Ref> all;
@@ -744,6 +787,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertNull(tag.getPeeledObjectId());
}
+ @Test
public void testGetRef_PackedNotPeeled_WrongSort() throws IOException {
writePackedRefs("" + //
v1_0.name() + " refs/tags/v1.0\n" + //
@@ -773,6 +817,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertNull(tag.getPeeledObjectId());
}
+ @Test
public void testGetRefs_PackedWithPeeled() throws IOException {
Map<String, Ref> all;
@@ -807,6 +852,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertEquals(v1_0.getObject(), tag.getPeeledObjectId());
}
+ @Test
public void testGetRef_EmptyDatabase() throws IOException {
Ref r;
@@ -825,6 +871,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertNull(refdir.getRef("v1.0"));
}
+ @Test
public void testGetRef_FetchHead() throws IOException {
// This is an odd special case where we need to make sure we read
// exactly the first 40 bytes of the file and nothing further on
@@ -841,6 +888,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertNull(r.getPeeledObjectId());
}
+ @Test
public void testGetRef_AnyHeadWithGarbage() throws IOException {
write(new File(diskRepo.getDirectory(), "refs/heads/A"), A.name()
+ "012345 . this is not a standard reference\n"
@@ -854,12 +902,14 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertNull(r.getPeeledObjectId());
}
+ @Test
public void testGetRefs_CorruptSymbolicReference() throws IOException {
String name = "refs/heads/A";
writeLooseRef(name, "ref: \n");
assertTrue(refdir.getRefs(RefDatabase.ALL).isEmpty());
}
+ @Test
public void testGetRef_CorruptSymbolicReference() throws IOException {
String name = "refs/heads/A";
writeLooseRef(name, "ref: \n");
@@ -872,6 +922,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
}
}
+ @Test
public void testGetRefs_CorruptObjectIdReference() throws IOException {
String name = "refs/heads/A";
String content = "zoo" + A.name();
@@ -879,6 +930,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertTrue(refdir.getRefs(RefDatabase.ALL).isEmpty());
}
+ @Test
public void testGetRef_CorruptObjectIdReference() throws IOException {
String name = "refs/heads/A";
String content = "zoo" + A.name();
@@ -892,6 +944,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
}
}
+ @Test
public void testIsNameConflicting() throws IOException {
writeLooseRef("refs/heads/a/b", A);
writePackedRef("refs/heads/q", B);
@@ -913,6 +966,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertTrue(refdir.isNameConflicting("refs/heads/q/master"));
}
+ @Test
public void testPeelLooseTag() throws IOException {
writeLooseRef("refs/tags/v1_0", v1_0);
writeLooseRef("refs/tags/current", "ref: refs/tags/v1_0\n");
@@ -961,6 +1015,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
assertSame(tag_p2, refdir.peel(tag_p2));
}
+ @Test
public void testPeelCommit() throws IOException {
writeLooseRef("refs/heads/master", A);

Back to the top