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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
* Copyright (C) 2014, Sven Selberg <sven.selberg@sonymobile.com> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* https://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.revwalk;
import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jgit.lib.Ref;
import org.junit.Test;
public class RevWalkMergedIntoTest extends RevWalkTestCase {
@Test
public void testOldCommitWalk() throws Exception {
/*
* Sometimes a merge is performed on a machine with faulty time.
* This makes the traversal of the graph, when trying to find out if B
* is merged into T, complex since the algorithm uses the time stamps
* of commits to find the best route.
* When for example O(ld) has a very old time stamp compared to one of the
* commits (N(ew)) on the upper route between T and F(alse base), the route
* to False is deemed the better option even though the alternate route leeds
* to B(ase) which was the commit we were after.
*
* o---o---o---o---N
* / \
* / o---o---o---O---T
* / /
* ---F---B
*
* This test is asserting that isMergedInto(B, T) returns true even
* under those circumstances.
*/
final int threeDaysInSecs = 3 * 24 * 60 * 60;
final RevCommit f = commit();
final RevCommit b = commit(f);
final RevCommit o = commit(-threeDaysInSecs, commit(commit(commit(b))));
final RevCommit n = commit(commit(commit(commit(commit(f)))));
final RevCommit t = commit(n, o);
assertTrue(rw.isMergedInto(b, t));
}
@Test
public void testGetMergedInto() throws Exception {
/*
* i
* / \
* A o
* / \ \
* o1 o2 E
* / \ / \
* B C D
*/
String b = "refs/heads/b";
String c = "refs/heads/c";
String d = "refs/heads/d";
String e = "refs/heads/e";
final RevCommit i = commit();
final RevCommit a = commit(i);
final RevCommit o1 = commit(a);
final RevCommit o2 = commit(a);
createBranch(commit(o1), b);
createBranch(commit(o1, o2), c);
createBranch(commit(o2), d);
createBranch(commit(commit(i)), e);
List<String> modifiedResult = rw.getMergedInto(a, getRefs())
.stream().map(Ref::getName).collect(Collectors.toList());
assertTrue(modifiedResult.size() == 3);
assertTrue(modifiedResult.contains(b));
assertTrue(modifiedResult.contains(c));
assertTrue(modifiedResult.contains(d));
}
@Test
public void testIsMergedIntoAny() throws Exception {
/*
* i
* / \
* A o
* / \
* o C
* /
* B
*/
String b = "refs/heads/b";
String c = "refs/heads/c";
final RevCommit i = commit();
final RevCommit a = commit(i);
createBranch(commit(commit(a)), b);
createBranch(commit(commit(i)), c);
assertTrue( rw.isMergedIntoAny(a, getRefs()));
}
@Test
public void testIsMergedIntoAll() throws Exception {
/*
*
* A
* / \
* o1 o2
* / \ / \
* B C D
*/
String b = "refs/heads/b";
String c = "refs/heads/c";
String d = "refs/heads/c";
final RevCommit a = commit();
final RevCommit o1 = commit(a);
final RevCommit o2 = commit(a);
createBranch(commit(o1), b);
createBranch(commit(o1, o2), c);
createBranch(commit(o2), d);
assertTrue(rw.isMergedIntoAll(a, getRefs()));
}
}
|