Unverified Commit 9aa049d4 by Patrick Steinhardt Committed by GitHub

Merge pull request #5020 from implausible/fix/gitignore-negation

Negation of subdir ignore causes other subdirs to be unignored
parents 5f188c48 d87441f2
...@@ -429,18 +429,6 @@ bool git_attr_fnmatch__match( ...@@ -429,18 +429,6 @@ bool git_attr_fnmatch__match(
return (p_fnmatch(match->pattern, relpath, flags) != FNM_NOMATCH); 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); return (p_fnmatch(match->pattern, filename, flags) != FNM_NOMATCH);
} }
......
...@@ -372,3 +372,28 @@ void test_attr_ignore__case_sensitive_unignore_does_nothing(void) ...@@ -372,3 +372,28 @@ void test_attr_ignore__case_sensitive_unignore_does_nothing(void)
assert_is_ignored(true, "case/file"); 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");
}
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