1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.revwalk;
11
12 import static org.junit.Assert.assertTrue;
13
14 import java.util.List;
15 import java.util.stream.Collectors;
16 import org.eclipse.jgit.lib.Ref;
17 import org.junit.Test;
18
19 public class RevWalkMergedIntoTest extends RevWalkTestCase {
20
21 @Test
22 public void testOldCommitWalk() throws Exception {
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 final int threeDaysInSecs = 3 * 24 * 60 * 60;
43 final RevCommit f = commit();
44 final RevCommit b = commit(f);
45 final RevCommit o = commit(-threeDaysInSecs, commit(commit(commit(b))));
46 final RevCommit n = commit(commit(commit(commit(commit(f)))));
47 final RevCommit t = commit(n, o);
48 assertTrue(rw.isMergedInto(b, t));
49 }
50
51 @Test
52 public void testGetMergedInto() throws Exception {
53
54
55
56
57
58
59
60
61
62 String b = "refs/heads/b";
63 String c = "refs/heads/c";
64 String d = "refs/heads/d";
65 String e = "refs/heads/e";
66 final RevCommit i = commit();
67 final RevCommit a = commit(i);
68 final RevCommit o1 = commit(a);
69 final RevCommit o2 = commit(a);
70 createBranch(commit(o1), b);
71 createBranch(commit(o1, o2), c);
72 createBranch(commit(o2), d);
73 createBranch(commit(commit(i)), e);
74
75 List<String> modifiedResult = rw.getMergedInto(a, getRefs())
76 .stream().map(Ref::getName).collect(Collectors.toList());
77
78 assertTrue(modifiedResult.size() == 3);
79 assertTrue(modifiedResult.contains(b));
80 assertTrue(modifiedResult.contains(c));
81 assertTrue(modifiedResult.contains(d));
82 }
83
84 @Test
85 public void testIsMergedIntoAny() throws Exception {
86
87
88
89
90
91
92
93
94
95 String b = "refs/heads/b";
96 String c = "refs/heads/c";
97 final RevCommit i = commit();
98 final RevCommit a = commit(i);
99 createBranch(commit(commit(a)), b);
100 createBranch(commit(commit(i)), c);
101
102 assertTrue(rw.isMergedIntoAny(a, getRefs()));
103 }
104
105 @Test
106 public void testIsMergedIntoAll() throws Exception {
107
108
109
110
111
112
113
114
115
116 String b = "refs/heads/b";
117 String c = "refs/heads/c";
118 String d = "refs/heads/c";
119 final RevCommit a = commit();
120 final RevCommit o1 = commit(a);
121 final RevCommit o2 = commit(a);
122 createBranch(commit(o1), b);
123 createBranch(commit(o1, o2), c);
124 createBranch(commit(o2), d);
125
126 assertTrue(rw.isMergedIntoAll(a, getRefs()));
127 }
128
129 @Test
130 public void testMergeIntoAnnotatedTag() throws Exception {
131
132
133
134
135
136
137
138 String c = "refs/heads/c";
139 String v1 = "refs/tags/v1";
140 final RevCommit a = commit();
141 final RevCommit b = commit(a);
142 createBranch(commit(b), c);
143 createBranch(tag("v1", b), v1);
144
145 assertTrue(rw.isMergedIntoAll(a, getRefs()));
146 }
147 }