1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.revwalk;
12
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.fail;
15
16 import org.eclipse.jgit.revwalk.filter.RevFilter;
17 import org.eclipse.jgit.treewalk.filter.TreeFilter;
18 import org.junit.Test;
19
20 public class RevWalkMergeBaseTest extends RevWalkTestCase {
21 @Test
22 public void testNone() throws Exception {
23 final RevCommit c1 = commit(commit(commit()));
24 final RevCommit c2 = commit(commit(commit()));
25
26 rw.setRevFilter(RevFilter.MERGE_BASE);
27 markStart(c1);
28 markStart(c2);
29 assertNull(rw.next());
30 }
31
32 @Test
33 public void testDisallowTreeFilter() throws Exception {
34 final RevCommit c1 = commit();
35 final RevCommit c2 = commit();
36
37 rw.setRevFilter(RevFilter.MERGE_BASE);
38 rw.setTreeFilter(TreeFilter.ANY_DIFF);
39 markStart(c1);
40 markStart(c2);
41 try {
42 assertNull(rw.next());
43 fail("did not throw IllegalStateException");
44 } catch (IllegalStateException ise) {
45
46 }
47 }
48
49 @Test
50 public void testSimple() throws Exception {
51 final RevCommit a = commit();
52 final RevCommit b = commit(a);
53 final RevCommit c1 = commit(commit(commit(commit(commit(b)))));
54 final RevCommit c2 = commit(commit(commit(commit(commit(b)))));
55
56 rw.setRevFilter(RevFilter.MERGE_BASE);
57 markStart(c1);
58 markStart(c2);
59 assertCommit(b, rw.next());
60 assertNull(rw.next());
61 }
62
63 @Test
64 public void testMultipleHeads_SameBase1() throws Exception {
65 final RevCommit a = commit();
66 final RevCommit b = commit(a);
67 final RevCommit c1 = commit(commit(commit(commit(commit(b)))));
68 final RevCommit c2 = commit(commit(commit(commit(commit(b)))));
69 final RevCommit c3 = commit(commit(commit(b)));
70
71 rw.setRevFilter(RevFilter.MERGE_BASE);
72 markStart(c1);
73 markStart(c2);
74 markStart(c3);
75 assertCommit(b, rw.next());
76 assertNull(rw.next());
77 }
78
79 @Test
80 public void testMultipleHeads_SameBase2() throws Exception {
81 final RevCommit a = commit();
82 final RevCommit b = commit(a);
83 final RevCommit c = commit(b);
84 final RevCommit d1 = commit(commit(commit(commit(commit(b)))));
85 final RevCommit d2 = commit(commit(commit(commit(commit(c)))));
86 final RevCommit d3 = commit(commit(commit(c)));
87
88 rw.setRevFilter(RevFilter.MERGE_BASE);
89 markStart(d1);
90 markStart(d2);
91 markStart(d3);
92 assertCommit(b, rw.next());
93 assertNull(rw.next());
94 }
95
96 @Test
97 public void testCrissCross() throws Exception {
98
99
100
101
102
103 final RevCommit a = commit();
104 final RevCommit b = commit(a);
105 final RevCommit c = commit(a);
106 final RevCommit d = commit(b, c);
107 final RevCommit e = commit(c, b);
108
109 rw.setRevFilter(RevFilter.MERGE_BASE);
110 markStart(d);
111 markStart(e);
112 assertCommit(c, rw.next());
113 assertCommit(b, rw.next());
114 assertNull(rw.next());
115 }
116
117 @Test
118 public void testInconsistentCommitTimes() throws Exception {
119
120
121
122
123
124
125
126
127
128
129 final RevCommit a = commit(2);
130 final RevCommit b = commit(-1, a);
131 final RevCommit c = commit(2, b, a);
132 final RevCommit d = commit(1, b);
133
134 rw.setRevFilter(RevFilter.MERGE_BASE);
135 markStart(d);
136 markStart(c);
137 assertCommit(b, rw.next());
138 assertNull(rw.next());
139 }
140
141 }