summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Sohrt <sohrt@his.de>2023-04-28 13:45:15 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2023-05-09 10:51:29 +0200
commite6f216119f2624db1e51f3414a3fec7dc3d67a2f (patch)
tree3ac1e340ffd8bb704a8d1b34c8410563dac89970
parent73f9f55e3b87a8fa9f9f5d40b6ace6a09fbbc16b (diff)
downloadjgit-e6f216119f2624db1e51f3414a3fec7dc3d67a2f.tar.gz
jgit-e6f216119f2624db1e51f3414a3fec7dc3d67a2f.zip
RewriteGeneratorTest: Introduce test cases for the RewriteGenerator
Bug: 577948 Signed-off-by: Simon Sohrt <sohrt@his.de> Change-Id: I5af1a43d49379e2417611eaacdd5f06be8147bc4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RewriteGeneratorTest.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RewriteGeneratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RewriteGeneratorTest.java
new file mode 100644
index 0000000000..04e372998c
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RewriteGeneratorTest.java
@@ -0,0 +1,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());
+ }
+}