summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov <loskutov@gmx.de>2015-07-16 00:23:37 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2015-07-21 01:23:40 +0200
commit4e7639bb656bf4c52d5925edfe34706a47c2548e (patch)
treedc0a67dbb02400a799d138cd19de6ec1faecb10f
parentdfed946f10e17e4862328f3e6c1912618e33193f (diff)
downloadjgit-4e7639bb656bf4c52d5925edfe34706a47c2548e.tar.gz
jgit-4e7639bb656bf4c52d5925edfe34706a47c2548e.zip
Don't keep empty ignore rules in the ignore node list
Change-Id: Icd893dfaba06561bbe5cc60ebf866ec5d8301c22 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java22
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java5
3 files changed, 33 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
index 17e2e9961e..9c23f3ca35 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
@@ -44,12 +44,15 @@ package org.eclipse.jgit.ignore;
import static org.eclipse.jgit.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.jgit.errors.CorruptObjectException;
@@ -324,6 +327,15 @@ public class IgnoreNodeTest extends RepositoryTestCase {
}
@Test
+ public void testEmptyIgnoreRules() throws IOException {
+ IgnoreNode node = new IgnoreNode();
+ node.parse(writeToString("", "#", "!", "[[=a=]]"));
+ assertEquals(new ArrayList<>(), node.getRules());
+ node.parse(writeToString(" ", " / "));
+ assertEquals(2, node.getRules().size());
+ }
+
+ @Test
public void testSlashOnlyMatchesDirectory() throws IOException {
writeIgnoreFile(".gitignore", "out/");
writeTrashFile("out", "");
@@ -472,4 +484,12 @@ public class IgnoreNodeTest extends RepositoryTestCase {
data.append(line + "\n");
writeTrashFile(name, data.toString());
}
+
+ private InputStream writeToString(String... rules) throws IOException {
+ StringBuilder data = new StringBuilder();
+ for (String line : rules) {
+ data.append(line + "\n");
+ }
+ return new ByteArrayInputStream(data.toString().getBytes("UTF-8"));
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java
index 892d5ef8f5..e376cbba5d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java
@@ -188,6 +188,14 @@ public class FastIgnoreRule {
return !inverse;
}
+ /**
+ * @return true if the rule never matches (comment line or broken pattern)
+ * @since 4.1
+ */
+ public boolean isEmpty() {
+ return matcher == NO_MATCH;
+ }
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java
index b20e525f5f..8b1244ed1b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java
@@ -110,7 +110,10 @@ public class IgnoreNode {
String txt;
while ((txt = br.readLine()) != null) {
if (txt.length() > 0 && !txt.startsWith("#") && !txt.equals("/")) { //$NON-NLS-1$ //$NON-NLS-2$
- rules.add(new FastIgnoreRule(txt));
+ FastIgnoreRule rule = new FastIgnoreRule(txt);
+ if (!rule.isEmpty()) {
+ rules.add(rule);
+ }
}
}
}