From f4dae204a6a2a1a85e8a90a5e89187f3415099e3 Mon Sep 17 00:00:00 2001 From: Robin Stocker Date: Tue, 3 Dec 2013 22:25:40 +0100 Subject: [PATCH] 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 Signed-off-by: Robin Stocker --- .../org/eclipse/jgit/ignore/IgnoreMatcherTest.java | 12 ++++++++++++ .../src/org/eclipse/jgit/ignore/IgnoreRule.java | 1 + 2 files changed, 13 insertions(+) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherTest.java index d911efc1d..aa98696b2 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherTest.java @@ -340,6 +340,18 @@ public void testGetters() { 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. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreRule.java b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreRule.java index e0c780fee..980f2094b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreRule.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreRule.java @@ -198,6 +198,7 @@ public boolean isMatch(String target, boolean isDirectory) { } } else { + matcher.reset(); matcher.append(target); if (matcher.isMatch()) return true;