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.

RevWalkMergeBaseTest.java 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (C) 2009, Google Inc.
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.revwalk;
  44. import static org.junit.Assert.assertNull;
  45. import static org.junit.Assert.fail;
  46. import org.eclipse.jgit.revwalk.filter.RevFilter;
  47. import org.eclipse.jgit.treewalk.filter.TreeFilter;
  48. import org.junit.Test;
  49. public class RevWalkMergeBaseTest extends RevWalkTestCase {
  50. @Test
  51. public void testNone() throws Exception {
  52. final RevCommit c1 = commit(commit(commit()));
  53. final RevCommit c2 = commit(commit(commit()));
  54. rw.setRevFilter(RevFilter.MERGE_BASE);
  55. markStart(c1);
  56. markStart(c2);
  57. assertNull(rw.next());
  58. }
  59. @Test
  60. public void testDisallowTreeFilter() throws Exception {
  61. final RevCommit c1 = commit();
  62. final RevCommit c2 = commit();
  63. rw.setRevFilter(RevFilter.MERGE_BASE);
  64. rw.setTreeFilter(TreeFilter.ANY_DIFF);
  65. markStart(c1);
  66. markStart(c2);
  67. try {
  68. assertNull(rw.next());
  69. fail("did not throw IllegalStateException");
  70. } catch (IllegalStateException ise) {
  71. // expected result
  72. }
  73. }
  74. @Test
  75. public void testSimple() throws Exception {
  76. final RevCommit a = commit();
  77. final RevCommit b = commit(a);
  78. final RevCommit c1 = commit(commit(commit(commit(commit(b)))));
  79. final RevCommit c2 = commit(commit(commit(commit(commit(b)))));
  80. rw.setRevFilter(RevFilter.MERGE_BASE);
  81. markStart(c1);
  82. markStart(c2);
  83. assertCommit(b, rw.next());
  84. assertNull(rw.next());
  85. }
  86. @Test
  87. public void testMultipleHeads_SameBase1() throws Exception {
  88. final RevCommit a = commit();
  89. final RevCommit b = commit(a);
  90. final RevCommit c1 = commit(commit(commit(commit(commit(b)))));
  91. final RevCommit c2 = commit(commit(commit(commit(commit(b)))));
  92. final RevCommit c3 = commit(commit(commit(b)));
  93. rw.setRevFilter(RevFilter.MERGE_BASE);
  94. markStart(c1);
  95. markStart(c2);
  96. markStart(c3);
  97. assertCommit(b, rw.next());
  98. assertNull(rw.next());
  99. }
  100. @Test
  101. public void testMultipleHeads_SameBase2() throws Exception {
  102. final RevCommit a = commit();
  103. final RevCommit b = commit(a);
  104. final RevCommit c = commit(b);
  105. final RevCommit d1 = commit(commit(commit(commit(commit(b)))));
  106. final RevCommit d2 = commit(commit(commit(commit(commit(c)))));
  107. final RevCommit d3 = commit(commit(commit(c)));
  108. rw.setRevFilter(RevFilter.MERGE_BASE);
  109. markStart(d1);
  110. markStart(d2);
  111. markStart(d3);
  112. assertCommit(b, rw.next());
  113. assertNull(rw.next());
  114. }
  115. @Test
  116. public void testCrissCross() throws Exception {
  117. // See http://marc.info/?l=git&m=111463358500362&w=2 for a nice
  118. // description of what this test is creating. We don't have a
  119. // clean merge base for d,e as they each merged the parents b,c
  120. // in different orders.
  121. //
  122. final RevCommit a = commit();
  123. final RevCommit b = commit(a);
  124. final RevCommit c = commit(a);
  125. final RevCommit d = commit(b, c);
  126. final RevCommit e = commit(c, b);
  127. rw.setRevFilter(RevFilter.MERGE_BASE);
  128. markStart(d);
  129. markStart(e);
  130. assertCommit(c, rw.next());
  131. assertCommit(b, rw.next());
  132. assertNull(rw.next());
  133. }
  134. @Test
  135. public void testInconsistentCommitTimes() throws Exception {
  136. // When commit times are inconsistent (a parent is younger than a child)
  137. // make sure that not both, parent and child, are reported as merge
  138. // base. In the following repo the merge base between C,D should be B.
  139. // But when A is younger than B the MergeBaseGenerator used to generate
  140. // A before it detected that B is also a merge base.
  141. //
  142. // +---C
  143. // / /
  144. // A---B---D
  145. final RevCommit a = commit(2);
  146. final RevCommit b = commit(-1, a);
  147. final RevCommit c = commit(2, b, a);
  148. final RevCommit d = commit(1, b);
  149. rw.setRevFilter(RevFilter.MERGE_BASE);
  150. markStart(d);
  151. markStart(c);
  152. assertCommit(b, rw.next());
  153. assertNull(rw.next());
  154. }
  155. }