diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-03-29 13:28:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-29 13:28:59 +0100 |
commit | 9aa049d4c1578cfd73ce66801fe2575632296060 (patch) | |
tree | 8045fcc18aeb7dd3e182028f0b936706fe8319b6 | |
parent | 5f188c48aaf0acbdc9b0b1637ff4159341e6c9a1 (diff) | |
parent | d87441f2bdeba5f1c68c56366247eebd612c732a (diff) | |
download | libgit2-9aa049d4c1578cfd73ce66801fe2575632296060.tar.gz |
Merge pull request #5020 from implausible/fix/gitignore-negation
Negation of subdir ignore causes other subdirs to be unignored
-rw-r--r-- | src/attr_file.c | 12 | ||||
-rw-r--r-- | tests/attr/ignore.c | 25 |
2 files changed, 25 insertions, 12 deletions
diff --git a/src/attr_file.c b/src/attr_file.c index 40c72ea04..8619647a3 100644 --- a/src/attr_file.c +++ b/src/attr_file.c @@ -429,18 +429,6 @@ bool git_attr_fnmatch__match( return (p_fnmatch(match->pattern, relpath, flags) != FNM_NOMATCH); } - /* if path is a directory prefix of a negated pattern, then match */ - if ((match->flags & GIT_ATTR_FNMATCH_NEGATIVE) && path->is_dir) { - size_t pathlen = strlen(relpath); - bool prefixed = (pathlen <= match->length) && - ((match->flags & GIT_ATTR_FNMATCH_ICASE) ? - !strncasecmp(match->pattern, relpath, pathlen) : - !strncmp(match->pattern, relpath, pathlen)); - - if (prefixed && git_path_at_end_of_segment(&match->pattern[pathlen])) - return true; - } - return (p_fnmatch(match->pattern, filename, flags) != FNM_NOMATCH); } diff --git a/tests/attr/ignore.c b/tests/attr/ignore.c index 165e2ba09..110304a81 100644 --- a/tests/attr/ignore.c +++ b/tests/attr/ignore.c @@ -372,3 +372,28 @@ void test_attr_ignore__case_sensitive_unignore_does_nothing(void) assert_is_ignored(true, "case/file"); } + +void test_attr_ignore__ignored_subdirfiles_with_subdir_rule(void) +{ + cl_git_rewritefile( + "attr/.gitignore", + "dir/*\n" + "!dir/sub1/sub2/**\n"); + + assert_is_ignored(true, "dir/a.test"); + assert_is_ignored(true, "dir/sub1/a.test"); + assert_is_ignored(true, "dir/sub1/sub2"); +} + +void test_attr_ignore__ignored_subdirfiles_with_negations(void) +{ + cl_git_rewritefile( + "attr/.gitignore", + "dir/*\n" + "!dir/a.test\n"); + + assert_is_ignored(false, "dir/a.test"); + assert_is_ignored(true, "dir/b.test"); + assert_is_ignored(true, "dir/sub1/c.test"); +} + |