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>
This commit is contained in:
parent
b98c84eb88
commit
dfed946f10
|
@ -374,6 +374,67 @@ public void testNoPatterns() throws IOException {
|
|||
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());
|
||||
|
|
|
@ -109,9 +109,9 @@ public void parse(InputStream in) throws IOException {
|
|||
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…
Reference in New Issue