1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.pgm;
12
13 import static org.junit.Assert.assertEquals;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.jgit.api.Git;
19 import org.eclipse.jgit.lib.CLIRepositoryTestCase;
20 import org.eclipse.jgit.revwalk.RevCommit;
21 import org.junit.Before;
22 import org.junit.Test;
23
24 public class RevListTest extends CLIRepositoryTestCase {
25
26 private Git git;
27
28 @Override
29 @Before
30 public void setUp() throws Exception {
31 super.setUp();
32 git = new Git(db);
33 }
34
35 @Test
36 public void testWithParentsFlag() throws Exception {
37 List<RevCommit> commits = createCommitsForParentsFlag(git);
38 String result = toString(
39 execute("git rev-list HEAD --parents -- Test.txt"));
40
41 String expect = toString(
42 commits.get(3).name() + ' ' + commits.get(1).name(),
43 commits.get(1).name());
44
45 assertEquals(expect, result);
46 }
47
48 @Test
49 public void testWithoutParentsFlag() throws Exception {
50 List<RevCommit> commits = createCommitsForParentsFlag(git);
51 String result = toString(execute("git rev-list HEAD -- Test.txt"));
52
53 String expect = toString(commits.get(3).name(), commits.get(1).name());
54
55 assertEquals(expect, result);
56 }
57
58 private List<RevCommit> createCommitsForParentsFlag(Git repo)
59 throws Exception {
60 List<RevCommit> commits = new ArrayList<>();
61 writeTrashFile("Test1.txt", "Hello world");
62 repo.add().addFilepattern("Test1.txt").call();
63 commits.add(repo.commit().setMessage("commit#0").call());
64 writeTrashFile("Test.txt", "Hello world!");
65 repo.add().addFilepattern("Test.txt").call();
66 commits.add(repo.commit().setMessage("commit#1").call());
67 writeTrashFile("Test1.txt", "Hello world!!");
68 repo.add().addFilepattern("Test1.txt").call();
69 commits.add(repo.commit().setMessage("commit#2").call());
70 writeTrashFile("Test.txt", "Hello world!!!");
71 repo.add().addFilepattern("Test.txt").call();
72 commits.add(repo.commit().setMessage("commit#3").call());
73 return commits;
74 }
75 }