aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test/tst/org/eclipse
diff options
context:
space:
mode:
authorkylezhao <kylezhao@tencent.com>2021-03-30 11:04:12 +0800
committerChristian Halstrick <christian.halstrick@sap.com>2021-05-26 10:14:22 +0200
commit46a702ef418e9f7723dac10d94460a4f3c0a689a (patch)
tree6deadcd1badcab22612f92098c922836bba258b4 /org.eclipse.jgit.pgm.test/tst/org/eclipse
parentc718e6059c0371dcde83d51f83f3031f934c34b7 (diff)
downloadjgit-46a702ef418e9f7723dac10d94460a4f3c0a689a.tar.gz
jgit-46a702ef418e9f7723dac10d94460a4f3c0a689a.zip
pgm: rewrite parents when --parents flag is passed
According to [1], we should rewrite parents in RevWalkTextBuiltin when variable parents is true. [1] https://git-scm.com/docs/git-rev-list#Documentation/git-rev-list.txt---parents Change-Id: If5dca3b280366969d0488fa895bc37253a797394 Signed-off-by: kylezhao <kylezhao@tencent.com>
Diffstat (limited to 'org.eclipse.jgit.pgm.test/tst/org/eclipse')
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RevListTest.java75
1 files changed, 75 insertions, 0 deletions
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RevListTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RevListTest.java
new file mode 100644
index 0000000000..06fddc29d9
--- /dev/null
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RevListTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2021, kylezhao <kylezhao@tencent.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.pgm;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.lib.CLIRepositoryTestCase;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.junit.Before;
+import org.junit.Test;
+
+public class RevListTest extends CLIRepositoryTestCase {
+
+ private Git git;
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ git = new Git(db);
+ }
+
+ @Test
+ public void testWithParentsFlag() throws Exception {
+ List<RevCommit> commits = createCommitsForParentsFlag(git);
+ String result = toString(
+ execute("git rev-list HEAD --parents -- Test.txt"));
+
+ String expect = toString(
+ commits.get(3).name() + ' ' + commits.get(1).name(),
+ commits.get(1).name());
+
+ assertEquals(expect, result);
+ }
+
+ @Test
+ public void testWithoutParentsFlag() throws Exception {
+ List<RevCommit> commits = createCommitsForParentsFlag(git);
+ String result = toString(execute("git rev-list HEAD -- Test.txt"));
+
+ String expect = toString(commits.get(3).name(), commits.get(1).name());
+
+ assertEquals(expect, result);
+ }
+
+ private List<RevCommit> createCommitsForParentsFlag(Git git)
+ throws Exception {
+ List<RevCommit> commits = new ArrayList<>();
+ writeTrashFile("Test1.txt", "Hello world");
+ git.add().addFilepattern("Test1.txt").call();
+ commits.add(git.commit().setMessage("commit#0").call());
+ writeTrashFile("Test.txt", "Hello world!");
+ git.add().addFilepattern("Test.txt").call();
+ commits.add(git.commit().setMessage("commit#1").call());
+ writeTrashFile("Test1.txt", "Hello world!!");
+ git.add().addFilepattern("Test1.txt").call();
+ commits.add(git.commit().setMessage("commit#2").call());
+ writeTrashFile("Test.txt", "Hello world!!!");
+ git.add().addFilepattern("Test.txt").call();
+ commits.add(git.commit().setMessage("commit#3").call());
+ return commits;
+ }
+}