Ignore trailing whitespace in .gitignore files (as git itself does)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
diff --git a/src/ignore.c b/src/ignore.c
index 0dc23b5..8c22477 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -205,6 +205,16 @@ static int parse_ignore_file(
if (ignore_case)
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);
/*
diff --git a/tests/attr/ignore.c b/tests/attr/ignore.c
index 856e61f..d241c03 100644
--- a/tests/attr/ignore.c
+++ b/tests/attr/ignore.c
@@ -51,6 +51,16 @@ void test_attr_ignore__allow_root(void)
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)
{
cl_git_rewritefile("attr/.gitignore", "/\n\n/NewFolder\n/NewFolder/NewFolder");