Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

RevListTest.java 2.2KB

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