]> source.dussan.org Git - jgit.git/commitdiff
Fix IgnoreRule#isMatch returning wrong result due to missing reset 71/19271/1
authorRobin Stocker <robin@nibor.org>
Tue, 3 Dec 2013 21:25:40 +0000 (22:25 +0100)
committerRobin Stocker <robin@nibor.org>
Tue, 3 Dec 2013 21:30:14 +0000 (22:30 +0100)
The matcher has to be reset before using it, as was already done in the
other cases.

Bug: 423039
Change-Id: I87abaa7ad7f0aac8651db6e88d41427cacb4d776
Also-by: Ondrej Vrabec <ovrabec@netbeans.org>
Signed-off-by: Robin Stocker <robin@nibor.org>
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherTest.java
org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreRule.java

index d911efc1d1e05feb7bb5b90b479901bbdd946a76..aa98696b2494d3843213f6fd4b4859f06faee30a 100644 (file)
@@ -340,6 +340,18 @@ public class IgnoreMatcherTest {
                assertEquals(r.getPattern(), "/patter?");
        }
 
+       @Test
+       public void testResetState() {
+               String pattern = "/build/*";
+               String target = "/build";
+               // Don't use the assert methods of this class, as we want to test
+               // whether the state in IgnoreRule is reset properly
+               IgnoreRule r = new IgnoreRule(pattern);
+               // Result should be the same for the same inputs
+               assertFalse(r.isMatch(target, true));
+               assertFalse(r.isMatch(target, true));
+       }
+
        /**
         * Check for a match. If target ends with "/", match will assume that the
         * target is meant to be a directory.
index e0c780feecba5337ecd5ecc3162eca3713ff6aca..980f2094bdda3f47d280c99571098e5393fc591f 100644 (file)
@@ -198,6 +198,7 @@ public class IgnoreRule {
                        }
 
                } else {
+                       matcher.reset();
                        matcher.append(target);
                        if (matcher.isMatch())
                                return true;