Commit 5cb6a2c9 by David Turner

Ignore trailing whitespace in .gitignore files (as git itself does)

parent 4da74c83
...@@ -213,6 +213,16 @@ static int parse_ignore_file( ...@@ -213,6 +213,16 @@ static int parse_ignore_file(
if (ignore_case) if (ignore_case)
match->flags |= GIT_ATTR_FNMATCH_ICASE; match->flags |= GIT_ATTR_FNMATCH_ICASE;
while (match->length > 0) {
if (match->pattern[match->length - 1] == ' ' ||
match->pattern[match->length - 1] == '\t') {
match->pattern[match->length - 1] = 0;
match->length --;
} else {
break;
}
}
scan = git__next_line(scan); scan = git__next_line(scan);
/* /*
......
...@@ -51,6 +51,16 @@ void test_attr_ignore__allow_root(void) ...@@ -51,6 +51,16 @@ void test_attr_ignore__allow_root(void)
assert_is_ignored(false, "NewFolder/NewFolder/File.txt"); assert_is_ignored(false, "NewFolder/NewFolder/File.txt");
} }
void test_attr_ignore__ignore_space(void)
{
cl_git_rewritefile("attr/.gitignore", "/\n\n/NewFolder \n/NewFolder/NewFolder");
assert_is_ignored(false, "File.txt");
assert_is_ignored(true, "NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
}
void test_attr_ignore__ignore_root(void) void test_attr_ignore__ignore_root(void)
{ {
cl_git_rewritefile("attr/.gitignore", "/\n\n/NewFolder\n/NewFolder/NewFolder"); cl_git_rewritefile("attr/.gitignore", "/\n\n/NewFolder\n/NewFolder/NewFolder");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment