View Javadoc
1   /*
2    * Copyright (C) 2016, Christian Halstrick <christian.halstrick@sap.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  
11  package org.eclipse.jgit.revwalk;
12  
13  import static org.junit.Assert.assertNull;
14  import static org.junit.Assert.assertTrue;
15  
16  import org.junit.Test;
17  
18  public class RevWalkCarryFlagsTest extends RevWalkTestCase {
19  	/**
20  	 * Test that the uninteresting flag is carried over correctly. Every commit
21  	 * should have the uninteresting flag resulting in a RevWalk returning no
22  	 * commit.
23  	 *
24  	 * @throws Exception
25  	 */
26  	@Test
27  	public void testRevWalkCarryUninteresting_fastClock() throws Exception {
28  		final RevCommit a = commit();
29  		final RevCommit b = commit(a);
30  		final RevCommit c = commit(a);
31  		final RevCommit d = commit(c);
32  		final RevCommit e = commit(b, d);
33  
34  		markStart(d);
35  		markUninteresting(e);
36  		assertNull("Found an unexpected commit", rw.next());
37  	}
38  
39  	/**
40  	 * Similar to {@link #testRevWalkCarryUninteresting_fastClock()} but the
41  	 * last merge commit is created so fast that he has the same creationdate as
42  	 * the previous commit. This will cause the underlying {@link DateRevQueue}
43  	 * is not able to sort the commits in a way matching the topology. A parent
44  	 * (one of the commits which are merged) is handled before the child (the
45  	 * merge commit). This makes carrying over flags more complicated
46  	 *
47  	 * @throws Exception
48  	 */
49  	@Test
50  	public void testRevWalkCarryUninteresting_SlowClock() throws Exception {
51  		final RevCommit a = commit();
52  		final RevCommit b = commit(a);
53  		final RevCommit c = commit(a);
54  		final RevCommit d = commit(c);
55  		final RevCommit e = commit(0, b, d);
56  
57  		markStart(d);
58  		markUninteresting(e);
59  		assertNull("Found an unexpected commit", rw.next());
60  	}
61  
62  	/**
63  	 * Similar to {@link #testRevWalkCarryUninteresting_SlowClock()} but the
64  	 * last merge commit is created with a inconsistent creationdate. The merge
65  	 * commit has a older creationdate then one of the commits he is merging.
66  	 *
67  	 * @throws Exception
68  	 */
69  	@Test
70  	public void testRevWalkCarryUninteresting_WrongClock() throws Exception {
71  		final RevCommit a = commit();
72  		final RevCommit b = commit(a);
73  		final RevCommit c = commit(a);
74  		final RevCommit d = commit(c);
75  		final RevCommit e = commit(-1, b, d);
76  
77  		markStart(d);
78  		markUninteresting(e);
79  		assertNull("Found an unexpected commit", rw.next());
80  	}
81  
82  	/**
83  	 * Same as {@link #testRevWalkCarryUninteresting_SlowClock()} but this time
84  	 * we focus on the carrying over a custom flag.
85  	 *
86  	 * @throws Exception
87  	 */
88  	@Test
89  	public void testRevWalkCarryCustom_SlowClock() throws Exception {
90  		final RevCommit a = commit();
91  		final RevCommit b = commit(a);
92  		final RevCommit c = commit(a);
93  		final RevCommit d = commit(c);
94  		final RevCommit e = commit(0, b, d);
95  
96  		markStart(d);
97  		markStart(e);
98  		RevFlag customFlag = rw.newFlag("CUSTOM");
99  		e.flags |= customFlag.mask;
100 		rw.carry(customFlag);
101 
102 		// the merge commit has the flag and it should be carried over -> every
103 		// commit should have this flag
104 		int count = 0;
105 		for (RevCommit cm : rw) {
106 			assertTrue(
107 					"Found a commit which doesn't have the custom flag: " + cm,
108 					cm.has(customFlag));
109 			count++;
110 		}
111 		assertTrue("Didn't walked over all commits", count == 5);
112 	}
113 }