aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RewriteGeneratorTest.java
blob: 04e372998cc1afcd6d53fd030e015a4a27afe983 (plain)
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
/*
 * Copyright (C) 2023, HIS eG
 *
 * 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.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;

public class RewriteGeneratorTest extends RevWalkTestCase {

	@Test
	public void testRewriteGeneratorDoesNotExhaustPreviousGenerator()
			throws Exception {
		RevCommit a = commit();
		a.flags |= RevWalk.TREE_REV_FILTER_APPLIED;
		RevCommit b = commit(a);

		LIFORevQueue q = new LIFORevQueue();
		q.add(a);
		q.add(b);

		/*
		 * Since the TREE_REV_FILTER has been applied to commit a and the
		 * REWRITE flag has not been applied to commit a, the RewriteGenerator
		 * must not rewrite the parent of b and thus must not call the previous
		 * generator (since b already has its correct parent).
		 */
		RewriteGenerator rewriteGenerator = new RewriteGenerator(q);
		rewriteGenerator.next();

		assertNotNull(
				"Previous generator was unnecessarily exhausted by RewriteGenerator",
				q.next());
	}

	@Test
	public void testRewriteGeneratorRewritesParent() throws Exception {
		RevCommit a = commit();
		a.flags |= RevWalk.TREE_REV_FILTER_APPLIED;
		a.flags |= RevWalk.REWRITE;
		RevCommit b = commit(a);
		assertEquals(1, b.getParentCount());

		LIFORevQueue q = new LIFORevQueue();
		/*
		 * We are only adding commit b (and not a), because PendingGenerator
		 * should never emit a commit that has the REWRITE flag set.
		 */
		q.add(b);

		RewriteGenerator rewriteGenerator = new RewriteGenerator(q);
		RevCommit returnedB = rewriteGenerator.next();
		assertEquals(b.getId(), returnedB.getId());
		assertEquals(0, returnedB.getParentCount());
	}
}