1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.internal.storage.dfs;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertTrue;
14
15 import java.util.Set;
16
17 import org.eclipse.jgit.junit.TestRepository;
18 import org.eclipse.jgit.lib.ObjectIdRef;
19 import org.eclipse.jgit.lib.Ref;
20 import org.eclipse.jgit.lib.Ref.Storage;
21 import org.eclipse.jgit.revwalk.RevCommit;
22 import org.eclipse.jgit.revwalk.RevTag;
23 import org.junit.Test;
24
25 public class InMemoryRepositoryTest {
26
27 @Test
28 public void keepUpdateIndexPeelingTag() throws Exception {
29 InMemoryRepository repo = new InMemoryRepository(
30 new DfsRepositoryDescription());
31 try (TestRepository<InMemoryRepository> git = new TestRepository<>(
32 repo)) {
33 RevCommit commit = git.branch("master").commit()
34 .message("first commit").create();
35 RevTag tag = git.tag("v0.1", commit);
36 git.update("refs/tags/v0.1", tag);
37
38 Ref unpeeledTag = new ObjectIdRef.Unpeeled(Storage.LOOSE,
39 "refs/tags/v0.1", tag.getId(), 1000);
40
41 Ref peeledTag = repo.getRefDatabase().peel(unpeeledTag);
42 assertTrue(peeledTag instanceof ObjectIdRef.PeeledTag);
43 assertEquals(1000, peeledTag.getUpdateIndex());
44 }
45 }
46
47 @Test
48 public void keepUpdateIndexPeelingNonTag() throws Exception {
49 InMemoryRepository repo = new InMemoryRepository(
50 new DfsRepositoryDescription());
51 try (TestRepository<InMemoryRepository> git = new TestRepository<>(
52 repo)) {
53 RevCommit commit = git.branch("master").commit()
54 .message("first commit").create();
55
56 Ref unpeeledRef = new ObjectIdRef.Unpeeled(Storage.LOOSE,
57 "refs/heads/master", commit.getId(), 1000);
58 Ref peeledRef = repo.getRefDatabase().peel(unpeeledRef);
59 assertTrue(peeledRef instanceof ObjectIdRef.PeeledNonTag);
60 assertEquals(1000, peeledRef.getUpdateIndex());
61 }
62 }
63
64 @Test
65 public void sha1ToTip_ref() throws Exception {
66 InMemoryRepository repo = new InMemoryRepository(
67 new DfsRepositoryDescription());
68 try (TestRepository<InMemoryRepository> git = new TestRepository<>(
69 repo)) {
70 RevCommit commit = git.branch("master").commit()
71 .message("first commit").create();
72
73 Set<Ref> tipsWithSha1 = repo.getRefDatabase()
74 .getTipsWithSha1(commit.getId());
75 assertEquals(1, tipsWithSha1.size());
76 Ref ref = tipsWithSha1.iterator().next();
77 assertEquals(ref.getName(), "refs/heads/master");
78 assertEquals(commit.getId(), ref.getObjectId());
79 }
80 }
81
82 @Test
83 public void sha1ToTip_annotatedTag() throws Exception {
84 InMemoryRepository repo = new InMemoryRepository(
85 new DfsRepositoryDescription());
86 try (TestRepository<InMemoryRepository> git = new TestRepository<>(
87 repo)) {
88 RevCommit commit = git.commit()
89 .message("first commit").create();
90 RevTag tagObj = git.tag("v0.1", commit);
91 git.update("refs/tags/v0.1", tagObj);
92 Set<Ref> tipsWithSha1 = repo.getRefDatabase()
93 .getTipsWithSha1(commit.getId());
94 assertEquals(1, tipsWithSha1.size());
95 Ref ref = tipsWithSha1.iterator().next();
96 assertEquals(ref.getName(), "refs/tags/v0.1");
97 assertEquals(commit.getId(), ref.getPeeledObjectId());
98 }
99 }
100
101 @Test
102 public void sha1ToTip_tag() throws Exception {
103 InMemoryRepository repo = new InMemoryRepository(
104 new DfsRepositoryDescription());
105 try (TestRepository<InMemoryRepository> git = new TestRepository<>(
106 repo)) {
107 RevCommit commit = git.commit().message("first commit").create();
108 git.update("refs/tags/v0.2", commit);
109 Set<Ref> tipsWithSha1 = repo.getRefDatabase()
110 .getTipsWithSha1(commit.getId());
111 assertEquals(1, tipsWithSha1.size());
112 Ref ref = tipsWithSha1.iterator().next();
113 assertEquals(ref.getName(), "refs/tags/v0.2");
114 assertEquals(commit.getId(), ref.getObjectId());
115 }
116 }
117 }