You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RevWalkMergedIntoTest.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2014, Sven Selberg <sven.selberg@sonymobile.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.revwalk;
  11. import static org.junit.Assert.assertTrue;
  12. import java.util.List;
  13. import java.util.stream.Collectors;
  14. import org.eclipse.jgit.lib.Ref;
  15. import org.junit.Test;
  16. public class RevWalkMergedIntoTest extends RevWalkTestCase {
  17. @Test
  18. public void testOldCommitWalk() throws Exception {
  19. /*
  20. * Sometimes a merge is performed on a machine with faulty time.
  21. * This makes the traversal of the graph, when trying to find out if B
  22. * is merged into T, complex since the algorithm uses the time stamps
  23. * of commits to find the best route.
  24. * When for example O(ld) has a very old time stamp compared to one of the
  25. * commits (N(ew)) on the upper route between T and F(alse base), the route
  26. * to False is deemed the better option even though the alternate route leeds
  27. * to B(ase) which was the commit we were after.
  28. *
  29. * o---o---o---o---N
  30. * / \
  31. * / o---o---o---O---T
  32. * / /
  33. * ---F---B
  34. *
  35. * This test is asserting that isMergedInto(B, T) returns true even
  36. * under those circumstances.
  37. */
  38. final int threeDaysInSecs = 3 * 24 * 60 * 60;
  39. final RevCommit f = commit();
  40. final RevCommit b = commit(f);
  41. final RevCommit o = commit(-threeDaysInSecs, commit(commit(commit(b))));
  42. final RevCommit n = commit(commit(commit(commit(commit(f)))));
  43. final RevCommit t = commit(n, o);
  44. assertTrue(rw.isMergedInto(b, t));
  45. }
  46. @Test
  47. public void testGetMergedInto() throws Exception {
  48. /*
  49. * i
  50. * / \
  51. * A o
  52. * / \ \
  53. * o1 o2 E
  54. * / \ / \
  55. * B C D
  56. */
  57. String b = "refs/heads/b";
  58. String c = "refs/heads/c";
  59. String d = "refs/heads/d";
  60. String e = "refs/heads/e";
  61. final RevCommit i = commit();
  62. final RevCommit a = commit(i);
  63. final RevCommit o1 = commit(a);
  64. final RevCommit o2 = commit(a);
  65. createBranch(commit(o1), b);
  66. createBranch(commit(o1, o2), c);
  67. createBranch(commit(o2), d);
  68. createBranch(commit(commit(i)), e);
  69. List<String> modifiedResult = rw.getMergedInto(a, getRefs())
  70. .stream().map(Ref::getName).collect(Collectors.toList());
  71. assertTrue(modifiedResult.size() == 3);
  72. assertTrue(modifiedResult.contains(b));
  73. assertTrue(modifiedResult.contains(c));
  74. assertTrue(modifiedResult.contains(d));
  75. }
  76. @Test
  77. public void testIsMergedIntoAny() throws Exception {
  78. /*
  79. * i
  80. * / \
  81. * A o
  82. * / \
  83. * o C
  84. * /
  85. * B
  86. */
  87. String b = "refs/heads/b";
  88. String c = "refs/heads/c";
  89. final RevCommit i = commit();
  90. final RevCommit a = commit(i);
  91. createBranch(commit(commit(a)), b);
  92. createBranch(commit(commit(i)), c);
  93. assertTrue( rw.isMergedIntoAny(a, getRefs()));
  94. }
  95. @Test
  96. public void testIsMergedIntoAll() throws Exception {
  97. /*
  98. *
  99. * A
  100. * / \
  101. * o1 o2
  102. * / \ / \
  103. * B C D
  104. */
  105. String b = "refs/heads/b";
  106. String c = "refs/heads/c";
  107. String d = "refs/heads/c";
  108. final RevCommit a = commit();
  109. final RevCommit o1 = commit(a);
  110. final RevCommit o2 = commit(a);
  111. createBranch(commit(o1), b);
  112. createBranch(commit(o1, o2), c);
  113. createBranch(commit(o2), d);
  114. assertTrue(rw.isMergedIntoAll(a, getRefs()));
  115. }
  116. }