1 /*
2 * Copyright (C) 2014, Sven Selberg <sven.selberg@sonymobile.com> and others
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Distribution License v. 1.0 which is available at
6 * https://www.eclipse.org/org/documents/edl-v10.php.
7 *
8 * SPDX-License-Identifier: BSD-3-Clause
9 */
10 package org.eclipse.jgit.revwalk;
11
12 import static org.junit.Assert.assertTrue;
13
14 import org.junit.Test;
15
16 public class RevWalkMergedIntoTest extends RevWalkTestCase {
17
18 @Test
19 public void testOldCommitWalk() throws Exception {
20 /*
21 * Sometimes a merge is performed on a machine with faulty time.
22 * This makes the traversal of the graph, when trying to find out if B
23 * is merged into T, complex since the algorithm uses the time stamps
24 * of commits to find the best route.
25 * When for example O(ld) has a very old time stamp compared to one of the
26 * commits (N(ew)) on the upper route between T and F(alse base), the route
27 * to False is deemed the better option even though the alternate route leeds
28 * to B(ase) which was the commit we were after.
29 *
30 * o---o---o---o---N
31 * / \
32 * / o---o---o---O---T
33 * / /
34 * ---F---B
35 *
36 * This test is asserting that isMergedInto(B, T) returns true even
37 * under those circumstances.
38 */
39 final int threeDaysInSecs = 3 * 24 * 60 * 60;
40 final RevCommit f = commit();
41 final RevCommit b = commit(f);
42 final RevCommit o = commit(-threeDaysInSecs, commit(commit(commit(b))));
43 final RevCommit n = commit(commit(commit(commit(commit(f)))));
44 final RevCommit t = commit(n, o);
45 assertTrue(rw.isMergedInto(b, t));
46 }
47 }