aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov <loskutov@gmx.de>2015-07-15 21:07:35 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2015-07-21 01:23:40 +0200
commitdfed946f10e17e4862328f3e6c1912618e33193f (patch)
tree86277bf51dc34044421bb68df7cdfb9a05e135c4
parentb98c84eb88e503e250274b62eaff000c071c62a4 (diff)
downloadjgit-dfed946f10e17e4862328f3e6c1912618e33193f.tar.gz
jgit-dfed946f10e17e4862328f3e6c1912618e33193f.zip
Allow leading/trailing spaces in ignore rules
According to [1] leading spaces are allowed in ignore rules and trailing spaces are allowed too if they are escaped via backslash. [1] https://www.kernel.org/pub/software/scm/git/docs/gitignore.html Bug: 472762 Change-Id: I5e3ae5599cb9e5d80072f38c82c20cbc9475a18a Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java61
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java4
2 files changed, 63 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 571f3186d7..17e2e9961e 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
@@ -375,6 +375,67 @@ public class IgnoreNodeTest extends RepositoryTestCase {
}
@Test
+ public void testLeadingSpaces() throws IOException {
+ writeTrashFile(" a/ a", "");
+ writeTrashFile(" a/ a", "");
+ writeTrashFile(" a/a", "");
+ writeTrashFile(" a/ a", "");
+ writeTrashFile(" a/ a", "");
+ writeTrashFile(" a/a", "");
+ writeIgnoreFile(".gitignore", " a", " a");
+ writeTrashFile("a/ a", "");
+ writeTrashFile("a/ a", "");
+ writeTrashFile("a/a", "");
+
+ beginWalk();
+ assertEntry(D, ignored, " a");
+ assertEntry(F, ignored, " a/ a");
+ assertEntry(F, ignored, " a/ a");
+ assertEntry(F, ignored, " a/a");
+ assertEntry(D, ignored, " a");
+ assertEntry(F, ignored, " a/ a");
+ assertEntry(F, ignored, " a/ a");
+ assertEntry(F, ignored, " a/a");
+ assertEntry(F, tracked, ".gitignore");
+ assertEntry(D, tracked, "a");
+ assertEntry(F, ignored, "a/ a");
+ assertEntry(F, ignored, "a/ a");
+ assertEntry(F, tracked, "a/a");
+ endWalk();
+ }
+
+ @Test
+ public void testTrailingSpaces() throws IOException {
+ writeTrashFile("a /a", "");
+ writeTrashFile("a /a ", "");
+ writeTrashFile("a /a ", "");
+ writeTrashFile("a /a", "");
+ writeTrashFile("a /a ", "");
+ writeTrashFile("a /a ", "");
+ writeTrashFile("a/a", "");
+ writeTrashFile("a/a ", "");
+ writeTrashFile("a/a ", "");
+
+ writeIgnoreFile(".gitignore", "a\\ ", "a \\ ");
+
+ beginWalk();
+ assertEntry(F, tracked, ".gitignore");
+ assertEntry(D, ignored, "a ");
+ assertEntry(F, ignored, "a /a");
+ assertEntry(F, ignored, "a /a ");
+ assertEntry(F, ignored, "a /a ");
+ assertEntry(D, ignored, "a ");
+ assertEntry(F, ignored, "a /a");
+ assertEntry(F, ignored, "a /a ");
+ assertEntry(F, ignored, "a /a ");
+ assertEntry(D, tracked, "a");
+ assertEntry(F, tracked, "a/a");
+ assertEntry(F, ignored, "a/a ");
+ assertEntry(F, ignored, "a/a ");
+ endWalk();
+ }
+
+ @Test
public void testToString() throws Exception {
assertEquals(Arrays.asList("").toString(), new IgnoreNode().toString());
assertEquals(Arrays.asList("hello").toString(),
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 efaeacd533..b20e525f5f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java
@@ -109,9 +109,9 @@ public class IgnoreNode {
BufferedReader br = asReader(in);
String txt;
while ((txt = br.readLine()) != null) {
- txt = txt.trim();
- if (txt.length() > 0 && !txt.startsWith("#") && !txt.equals("/")) //$NON-NLS-1$ //$NON-NLS-2$
+ if (txt.length() > 0 && !txt.startsWith("#") && !txt.equals("/")) { //$NON-NLS-1$ //$NON-NLS-2$
rules.add(new FastIgnoreRule(txt));
+ }
}
}