Skip to content

Commit bc3d406

Browse files
committed
fix check for ignoring of negate rules
gitignore rule like "*.pdf" should be negated by "!dir/test.pdf" even though one is inside a directory since *.pdf isn't restricted to any directory this is fixed by making wildcard match treat * like ** by excluding WM_PATHNAME flag when the rule isn't for a full path
1 parent 4f4b113 commit bc3d406

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/ignore.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static int does_negate_pattern(git_attr_fnmatch *rule, git_attr_fnmatch *neg)
101101
*/
102102
static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match)
103103
{
104-
int error = 0, wildmatch_flags;
104+
int error = 0, wildmatch_flags, effective_flags;
105105
size_t i;
106106
git_attr_fnmatch *rule;
107107
char *path;
@@ -141,8 +141,17 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match
141141
if (git_buf_oom(&buf))
142142
goto out;
143143

144+
/* if rule isn't for full path we match without PATHNAME flag
145+
as lines like *.txt should match something like dir/test.txt
146+
requiring * to also match /
147+
*/
148+
effective_flags = wildmatch_flags;
149+
if ((rule->flags & GIT_ATTR_FNMATCH_FULLPATH) == 0) {
150+
effective_flags &= ~WM_PATHNAME;
151+
}
152+
144153
/* if we found a match, we want to keep this rule */
145-
if ((wildmatch(git_buf_cstr(&buf), path, wildmatch_flags)) == WM_MATCH) {
154+
if ((wildmatch(git_buf_cstr(&buf), path, effective_flags)) == WM_MATCH) {
146155
*out = 1;
147156
error = 0;
148157
goto out;

0 commit comments

Comments
 (0)