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.assertEquals;
47 import static org.junit.Assert.assertNull;
48
49 import java.util.Collections;
50
51 import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
52 import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
53 import org.eclipse.jgit.treewalk.filter.TreeFilter;
54 import org.junit.Test;
55
56 public class RevWalkPathFilter1Test extends RevWalkTestCase {
57 protected void filter(final String path) {
58 rw.setTreeFilter(AndTreeFilter.create(PathFilterGroup
59 .createFromStrings(Collections.singleton(path)),
60 TreeFilter.ANY_DIFF));
61 }
62
63 @Test
64 public void testEmpty_EmptyTree() throws Exception {
65 final RevCommit a = commit();
66 filter("a");
67 markStart(a);
68 assertNull(rw.next());
69 }
70
71 @Test
72 public void testEmpty_NoMatch() throws Exception {
73 final RevCommit a = commit(tree(file("0", blob("0"))));
74 filter("a");
75 markStart(a);
76 assertNull(rw.next());
77 }
78
79 @Test
80 public void testSimple1() throws Exception {
81 final RevCommit a = commit(tree(file("0", blob("0"))));
82 filter("0");
83 markStart(a);
84 assertCommit(a, rw.next());
85 assertNull(rw.next());
86 }
87
88 @Test
89 public void testEdits_MatchNone() throws Exception {
90 final RevCommit a = commit(tree(file("0", blob("a"))));
91 final RevCommit b = commit(tree(file("0", blob("b"))), a);
92 final RevCommit c = commit(tree(file("0", blob("c"))), b);
93 final RevCommit d = commit(tree(file("0", blob("d"))), c);
94 filter("a");
95 markStart(d);
96 assertNull(rw.next());
97 }
98
99 @Test
100 public void testEdits_MatchAll() throws Exception {
101 final RevCommit a = commit(tree(file("0", blob("a"))));
102 final RevCommit b = commit(tree(file("0", blob("b"))), a);
103 final RevCommit c = commit(tree(file("0", blob("c"))), b);
104 final RevCommit d = commit(tree(file("0", blob("d"))), c);
105 filter("0");
106 markStart(d);
107 assertCommit(d, rw.next());
108 assertCommit(c, rw.next());
109 assertCommit(b, rw.next());
110 assertCommit(a, rw.next());
111 assertNull(rw.next());
112 }
113
114 @Test
115 public void testStringOfPearls_FilePath1() throws Exception {
116 final RevCommit a = commit(tree(file("d/f", blob("a"))));
117 final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
118 final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
119 filter("d/f");
120 markStart(c);
121
122 assertCommit(c, rw.next());
123 assertEquals(1, c.getParentCount());
124 assertCommit(a, c.getParent(0));
125
126 assertCommit(a, rw.next());
127 assertEquals(0, a.getParentCount());
128 assertNull(rw.next());
129 }
130
131 @Test
132 public void testStringOfPearls_FilePath1_NoParentRewriting()
133 throws Exception {
134 final RevCommit a = commit(tree(file("d/f", blob("a"))));
135 final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
136 final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
137 filter("d/f");
138 markStart(c);
139 rw.setRewriteParents(false);
140
141 assertCommit(c, rw.next());
142 assertEquals(1, c.getParentCount());
143 assertCommit(b, c.getParent(0));
144
145 assertCommit(a, rw.next());
146 assertEquals(0, a.getParentCount());
147 assertNull(rw.next());
148 }
149
150 @Test
151 public void testStringOfPearls_FilePath2() throws Exception {
152 final RevCommit a = commit(tree(file("d/f", blob("a"))));
153 final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
154 final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
155 final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
156 filter("d/f");
157 markStart(d);
158
159
160 assertCommit(c, rw.next());
161 assertEquals(1, c.getParentCount());
162 assertCommit(a, c.getParent(0));
163
164 assertCommit(a, rw.next());
165 assertEquals(0, a.getParentCount());
166 assertNull(rw.next());
167 }
168
169 @Test
170 public void testStringOfPearls_FilePath2_NoParentRewriting()
171 throws Exception {
172 final RevCommit a = commit(tree(file("d/f", blob("a"))));
173 final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
174 final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
175 final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
176 filter("d/f");
177 markStart(d);
178 rw.setRewriteParents(false);
179
180
181 assertCommit(c, rw.next());
182 assertEquals(1, c.getParentCount());
183 assertCommit(b, c.getParent(0));
184
185
186 assertCommit(a, rw.next());
187 assertEquals(0, a.getParentCount());
188 assertNull(rw.next());
189 }
190
191 @Test
192 public void testStringOfPearls_DirPath2() throws Exception {
193 final RevCommit a = commit(tree(file("d/f", blob("a"))));
194 final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
195 final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
196 final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
197 filter("d");
198 markStart(d);
199
200
201 assertCommit(c, rw.next());
202 assertEquals(1, c.getParentCount());
203 assertCommit(a, c.getParent(0));
204
205 assertCommit(a, rw.next());
206 assertEquals(0, a.getParentCount());
207 assertNull(rw.next());
208 }
209
210 @Test
211 public void testStringOfPearls_DirPath2_NoParentRewriting()
212 throws Exception {
213 final RevCommit a = commit(tree(file("d/f", blob("a"))));
214 final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
215 final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
216 final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
217 filter("d");
218 markStart(d);
219 rw.setRewriteParents(false);
220
221
222 assertCommit(c, rw.next());
223 assertEquals(1, c.getParentCount());
224 assertCommit(b, c.getParent(0));
225
226
227 assertCommit(a, rw.next());
228 assertEquals(0, a.getParentCount());
229 assertNull(rw.next());
230 }
231
232 @Test
233 public void testStringOfPearls_FilePath3() throws Exception {
234 final RevCommit a = commit(tree(file("d/f", blob("a"))));
235 final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
236 final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
237 final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
238 final RevCommit e = commit(tree(file("d/f", blob("b"))), d);
239 final RevCommit f = commit(tree(file("d/f", blob("b"))), e);
240 final RevCommit g = commit(tree(file("d/f", blob("b"))), f);
241 final RevCommit h = commit(tree(file("d/f", blob("b"))), g);
242 final RevCommit i = commit(tree(file("d/f", blob("c"))), h);
243 filter("d/f");
244 markStart(i);
245
246 assertCommit(i, rw.next());
247 assertEquals(1, i.getParentCount());
248 assertCommit(c, i.getParent(0));
249
250 assertCommit(c, rw.next());
251 assertEquals(1, c.getParentCount());
252 assertCommit(a, c.getParent(0));
253
254 assertCommit(a, rw.next());
255 assertEquals(0, a.getParentCount());
256 assertNull(rw.next());
257 }
258
259 @Test
260 public void testStringOfPearls_FilePath3_NoParentRewriting()
261 throws Exception {
262 final RevCommit a = commit(tree(file("d/f", blob("a"))));
263 final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
264 final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
265 final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
266 final RevCommit e = commit(tree(file("d/f", blob("b"))), d);
267 final RevCommit f = commit(tree(file("d/f", blob("b"))), e);
268 final RevCommit g = commit(tree(file("d/f", blob("b"))), f);
269 final RevCommit h = commit(tree(file("d/f", blob("b"))), g);
270 final RevCommit i = commit(tree(file("d/f", blob("c"))), h);
271 filter("d/f");
272 markStart(i);
273 rw.setRewriteParents(false);
274
275 assertCommit(i, rw.next());
276 assertEquals(1, i.getParentCount());
277 assertCommit(h, i.getParent(0));
278
279
280 assertCommit(c, rw.next());
281 assertEquals(1, c.getParentCount());
282 assertCommit(b, c.getParent(0));
283
284
285 assertCommit(a, rw.next());
286 assertEquals(0, a.getParentCount());
287 assertNull(rw.next());
288 }
289 }