Browse Source

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>
stable-4.1
Andrey Loskutov 10 years ago committed by Matthias Sohn
parent
commit
dfed946f10
  1. 61
      org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
  2. 4
      org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java

61
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java

@ -374,6 +374,67 @@ public class IgnoreNodeTest extends RepositoryTestCase {
endWalk();
}
@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());

4
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));
}
}
}

Loading…
Cancel
Save