Browse Source

Fix IgnoreRule#isMatch returning wrong result due to missing reset

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>
stable-3.3
Robin Stocker 11 years ago
parent
commit
f4dae204a6
  1. 12
      org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherTest.java
  2. 1
      org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreRule.java

12
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherTest.java

@ -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.

1
org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreRule.java

@ -198,6 +198,7 @@ public class IgnoreRule {
}
} else {
matcher.reset();
matcher.append(target);
if (matcher.isMatch())
return true;

Loading…
Cancel
Save