1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.revwalk;
45
46 import static org.junit.Assert.assertNull;
47
48 import java.io.File;
49 import java.io.IOException;
50
51 import org.eclipse.jgit.junit.JGitTestUtil;
52 import org.eclipse.jgit.lib.ObjectId;
53 import org.junit.Test;
54
55 public class RevWalkShallowTest extends RevWalkTestCase {
56
57
58
59 @Test
60 public void testDepth1() throws Exception {
61 final RevCommit a = commit();
62 final RevCommit b = commit(a);
63 final RevCommit c = commit(b);
64 final RevCommit d = commit(c);
65
66 createShallowFile(d);
67
68 rw.reset();
69 markStart(d);
70 assertCommit(d, rw.next());
71 assertNull(rw.next());
72 }
73
74 @Test
75 public void testDepth2() throws Exception {
76 final RevCommit a = commit();
77 final RevCommit b = commit(a);
78 final RevCommit c = commit(b);
79 final RevCommit d = commit(c);
80
81 createShallowFile(c);
82
83 rw.reset();
84 markStart(d);
85 assertCommit(d, rw.next());
86 assertCommit(c, rw.next());
87 assertNull(rw.next());
88 }
89
90 @Test
91 public void testDepth3() throws Exception {
92 final RevCommit a = commit();
93 final RevCommit b = commit(a);
94 final RevCommit c = commit(b);
95 final RevCommit d = commit(c);
96
97 createShallowFile(b);
98
99 rw.reset();
100 markStart(d);
101 assertCommit(d, rw.next());
102 assertCommit(c, rw.next());
103 assertCommit(b, rw.next());
104 assertNull(rw.next());
105 }
106
107 @Test
108 public void testMergeCommitOneParentShallow() throws Exception {
109 final RevCommit a = commit();
110 final RevCommit b = commit(a);
111 final RevCommit c = commit(b);
112 final RevCommit d = commit(b);
113 final RevCommit e = commit(d);
114 final RevCommit merge = commit(c, e);
115
116 createShallowFile(e);
117
118 rw.reset();
119 markStart(merge);
120 assertCommit(merge, rw.next());
121 assertCommit(e, rw.next());
122 assertCommit(c, rw.next());
123 assertCommit(b, rw.next());
124 assertCommit(a, rw.next());
125 assertNull(rw.next());
126 }
127
128 @Test
129 public void testMergeCommitEntirelyShallow() throws Exception {
130 final RevCommit a = commit();
131 final RevCommit b = commit(a);
132 final RevCommit c = commit(b);
133 final RevCommit d = commit(b);
134 final RevCommit e = commit(d);
135 final RevCommit merge = commit(c, e);
136
137 createShallowFile(c, e);
138
139 rw.reset();
140 markStart(merge);
141 assertCommit(merge, rw.next());
142 assertCommit(e, rw.next());
143 assertCommit(c, rw.next());
144 assertNull(rw.next());
145 }
146
147 @Test
148 public void testObjectDirectorySnapshot() throws Exception {
149 RevCommit a = commit();
150 RevCommit b = commit(a);
151 RevCommit c = commit(b);
152 RevCommit d = commit(c);
153
154 createShallowFile(d);
155
156 rw.reset();
157 markStart(d);
158 assertCommit(d, rw.next());
159 assertNull(rw.next());
160
161 rw = createRevWalk();
162 a = rw.lookupCommit(a);
163 b = rw.lookupCommit(b);
164 c = rw.lookupCommit(c);
165 d = rw.lookupCommit(d);
166
167 rw.reset();
168 markStart(d);
169 assertCommit(d, rw.next());
170 assertNull(rw.next());
171
172 createShallowFile(c);
173
174 rw = createRevWalk();
175 a = rw.lookupCommit(a);
176 b = rw.lookupCommit(b);
177 c = rw.lookupCommit(c);
178 d = rw.lookupCommit(d);
179
180 rw.reset();
181 markStart(d);
182 assertCommit(d, rw.next());
183 assertCommit(c, rw.next());
184 assertNull(rw.next());
185 }
186
187 private void createShallowFile(ObjectId... shallowCommits)
188 throws IOException {
189 final StringBuilder builder = new StringBuilder();
190 for (ObjectId commit : shallowCommits)
191 builder.append(commit.getName() + "\n");
192 JGitTestUtil.write(new File(db.getDirectory(), "shallow"),
193 builder.toString());
194 }
195 }