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.

RevWalkPathFilter1Test.java 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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.assertEquals;
  45. import static org.junit.Assert.assertNull;
  46. import java.util.Collections;
  47. import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
  48. import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
  49. import org.eclipse.jgit.treewalk.filter.TreeFilter;
  50. import org.junit.Test;
  51. public class RevWalkPathFilter1Test extends RevWalkTestCase {
  52. protected void filter(final String path) {
  53. rw.setTreeFilter(AndTreeFilter.create(PathFilterGroup
  54. .createFromStrings(Collections.singleton(path)),
  55. TreeFilter.ANY_DIFF));
  56. }
  57. @Test
  58. public void testEmpty_EmptyTree() throws Exception {
  59. final RevCommit a = commit();
  60. filter("a");
  61. markStart(a);
  62. assertNull(rw.next());
  63. }
  64. @Test
  65. public void testEmpty_NoMatch() throws Exception {
  66. final RevCommit a = commit(tree(file("0", blob("0"))));
  67. filter("a");
  68. markStart(a);
  69. assertNull(rw.next());
  70. }
  71. @Test
  72. public void testSimple1() throws Exception {
  73. final RevCommit a = commit(tree(file("0", blob("0"))));
  74. filter("0");
  75. markStart(a);
  76. assertCommit(a, rw.next());
  77. assertNull(rw.next());
  78. }
  79. @Test
  80. public void testEdits_MatchNone() throws Exception {
  81. final RevCommit a = commit(tree(file("0", blob("a"))));
  82. final RevCommit b = commit(tree(file("0", blob("b"))), a);
  83. final RevCommit c = commit(tree(file("0", blob("c"))), b);
  84. final RevCommit d = commit(tree(file("0", blob("d"))), c);
  85. filter("a");
  86. markStart(d);
  87. assertNull(rw.next());
  88. }
  89. @Test
  90. public void testEdits_MatchAll() throws Exception {
  91. final RevCommit a = commit(tree(file("0", blob("a"))));
  92. final RevCommit b = commit(tree(file("0", blob("b"))), a);
  93. final RevCommit c = commit(tree(file("0", blob("c"))), b);
  94. final RevCommit d = commit(tree(file("0", blob("d"))), c);
  95. filter("0");
  96. markStart(d);
  97. assertCommit(d, rw.next());
  98. assertCommit(c, rw.next());
  99. assertCommit(b, rw.next());
  100. assertCommit(a, rw.next());
  101. assertNull(rw.next());
  102. }
  103. @Test
  104. public void testStringOfPearls_FilePath1() throws Exception {
  105. final RevCommit a = commit(tree(file("d/f", blob("a"))));
  106. final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
  107. final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
  108. filter("d/f");
  109. markStart(c);
  110. assertCommit(c, rw.next());
  111. assertEquals(1, c.getParentCount());
  112. assertCommit(a, c.getParent(0)); // b was skipped
  113. assertCommit(a, rw.next());
  114. assertEquals(0, a.getParentCount());
  115. assertNull(rw.next());
  116. }
  117. @Test
  118. public void testStringOfPearls_FilePath2() throws Exception {
  119. final RevCommit a = commit(tree(file("d/f", blob("a"))));
  120. final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
  121. final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
  122. final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
  123. filter("d/f");
  124. markStart(d);
  125. // d was skipped
  126. assertCommit(c, rw.next());
  127. assertEquals(1, c.getParentCount());
  128. assertCommit(a, c.getParent(0)); // b was skipped
  129. assertCommit(a, rw.next());
  130. assertEquals(0, a.getParentCount());
  131. assertNull(rw.next());
  132. }
  133. @Test
  134. public void testStringOfPearls_DirPath2() throws Exception {
  135. final RevCommit a = commit(tree(file("d/f", blob("a"))));
  136. final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
  137. final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
  138. final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
  139. filter("d");
  140. markStart(d);
  141. // d was skipped
  142. assertCommit(c, rw.next());
  143. assertEquals(1, c.getParentCount());
  144. assertCommit(a, c.getParent(0)); // b was skipped
  145. assertCommit(a, rw.next());
  146. assertEquals(0, a.getParentCount());
  147. assertNull(rw.next());
  148. }
  149. @Test
  150. public void testStringOfPearls_FilePath3() throws Exception {
  151. final RevCommit a = commit(tree(file("d/f", blob("a"))));
  152. final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
  153. final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
  154. final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
  155. final RevCommit e = commit(tree(file("d/f", blob("b"))), d);
  156. final RevCommit f = commit(tree(file("d/f", blob("b"))), e);
  157. final RevCommit g = commit(tree(file("d/f", blob("b"))), f);
  158. final RevCommit h = commit(tree(file("d/f", blob("b"))), g);
  159. final RevCommit i = commit(tree(file("d/f", blob("c"))), h);
  160. filter("d/f");
  161. markStart(i);
  162. assertCommit(i, rw.next());
  163. assertEquals(1, i.getParentCount());
  164. assertCommit(c, i.getParent(0)); // h..d was skipped
  165. assertCommit(c, rw.next());
  166. assertEquals(1, c.getParentCount());
  167. assertCommit(a, c.getParent(0)); // b was skipped
  168. assertCommit(a, rw.next());
  169. assertEquals(0, a.getParentCount());
  170. assertNull(rw.next());
  171. }
  172. }