diff options
author | David Turner <dturner@twosigma.com> | 2017-10-29 12:28:43 -0400 |
---|---|---|
committer | David Turner <dturner@twosigma.com> | 2017-10-29 12:28:43 -0400 |
commit | 5cb6a2c946a071d43be3cdabf2f6d4417a4be694 (patch) | |
tree | 7740ddf672776de2b468926cb77e2b0bf8da0a17 | |
parent | 4da74c83e4263bb2d62c85af6188d223fd0157d6 (diff) | |
download | libgit2-5cb6a2c946a071d43be3cdabf2f6d4417a4be694.tar.gz |
Ignore trailing whitespace in .gitignore files (as git itself does)
-rw-r--r-- | src/ignore.c | 10 | ||||
-rw-r--r-- | tests/attr/ignore.c | 10 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/ignore.c b/src/ignore.c index f089dbeb5..615cd94bf 100644 --- a/src/ignore.c +++ b/src/ignore.c @@ -213,6 +213,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 856e61f90..d241c03b5 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"); |