Unverified Commit 84ce9746 by Edward Thomson Committed by GitHub

Merge pull request #5824 from palmin/fix-ignore-negate

fix check for ignoring of negate rules
parents e5649e10 6d2a6f3e
...@@ -101,7 +101,7 @@ static int does_negate_pattern(git_attr_fnmatch *rule, git_attr_fnmatch *neg) ...@@ -101,7 +101,7 @@ static int does_negate_pattern(git_attr_fnmatch *rule, git_attr_fnmatch *neg)
*/ */
static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match) static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match)
{ {
int error = 0, wildmatch_flags; int error = 0, wildmatch_flags, effective_flags;
size_t i; size_t i;
git_attr_fnmatch *rule; git_attr_fnmatch *rule;
char *path; char *path;
...@@ -141,8 +141,17 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match ...@@ -141,8 +141,17 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match
if (git_buf_oom(&buf)) if (git_buf_oom(&buf))
goto out; goto out;
/*
* if rule isn't for full path we match without PATHNAME flag
* as lines like *.txt should match something like dir/test.txt
* requiring * to also match /
*/
effective_flags = wildmatch_flags;
if (!(rule->flags & GIT_ATTR_FNMATCH_FULLPATH))
effective_flags &= ~WM_PATHNAME;
/* if we found a match, we want to keep this rule */ /* if we found a match, we want to keep this rule */
if ((wildmatch(git_buf_cstr(&buf), path, wildmatch_flags)) == WM_MATCH) { if ((wildmatch(git_buf_cstr(&buf), path, effective_flags)) == WM_MATCH) {
*out = 1; *out = 1;
error = 0; error = 0;
goto out; goto out;
...@@ -639,4 +648,3 @@ int git_ignore__check_pathspec_for_exact_ignores( ...@@ -639,4 +648,3 @@ int git_ignore__check_pathspec_for_exact_ignores(
return error; return error;
} }
...@@ -575,3 +575,11 @@ void test_ignore_path__negative_prefix_rule(void) ...@@ -575,3 +575,11 @@ void test_ignore_path__negative_prefix_rule(void)
assert_is_ignored(true, "ff"); assert_is_ignored(true, "ff");
assert_is_ignored(false, "f"); assert_is_ignored(false, "f");
} }
void test_ignore_path__negative_more_specific(void)
{
cl_git_rewritefile("attr/.gitignore", "*.txt\n!/dir/test.txt\n");
assert_is_ignored(true, "test.txt");
assert_is_ignored(false, "dir/test.txt");
assert_is_ignored(true, "outer/dir/test.txt");
}
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