Skip to content

Commit 8233f6e

Browse files
authored
Merge pull request libgit2#4386 from novalis/gitignore-ignore-space
ignore spaces in .gitignore files
2 parents 6f1e4f4 + 5cb6a2c commit 8233f6e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/ignore.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ static int parse_ignore_file(
213213
if (ignore_case)
214214
match->flags |= GIT_ATTR_FNMATCH_ICASE;
215215

216+
while (match->length > 0) {
217+
if (match->pattern[match->length - 1] == ' ' ||
218+
match->pattern[match->length - 1] == '\t') {
219+
match->pattern[match->length - 1] = 0;
220+
match->length --;
221+
} else {
222+
break;
223+
}
224+
}
225+
216226
scan = git__next_line(scan);
217227

218228
/*

tests/attr/ignore.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ void test_attr_ignore__allow_root(void)
5151
assert_is_ignored(false, "NewFolder/NewFolder/File.txt");
5252
}
5353

54+
void test_attr_ignore__ignore_space(void)
55+
{
56+
cl_git_rewritefile("attr/.gitignore", "/\n\n/NewFolder \n/NewFolder/NewFolder");
57+
58+
assert_is_ignored(false, "File.txt");
59+
assert_is_ignored(true, "NewFolder");
60+
assert_is_ignored(true, "NewFolder/NewFolder");
61+
assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
62+
}
63+
5464
void test_attr_ignore__ignore_root(void)
5565
{
5666
cl_git_rewritefile("attr/.gitignore", "/\n\n/NewFolder\n/NewFolder/NewFolder");

0 commit comments

Comments
 (0)