Skip to content

Commit 9aa049d

Browse files
authored
Merge pull request libgit2#5020 from implausible/fix/gitignore-negation
Negation of subdir ignore causes other subdirs to be unignored
2 parents 5f188c4 + d87441f commit 9aa049d

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/attr_file.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -429,18 +429,6 @@ bool git_attr_fnmatch__match(
429429
return (p_fnmatch(match->pattern, relpath, flags) != FNM_NOMATCH);
430430
}
431431

432-
/* if path is a directory prefix of a negated pattern, then match */
433-
if ((match->flags & GIT_ATTR_FNMATCH_NEGATIVE) && path->is_dir) {
434-
size_t pathlen = strlen(relpath);
435-
bool prefixed = (pathlen <= match->length) &&
436-
((match->flags & GIT_ATTR_FNMATCH_ICASE) ?
437-
!strncasecmp(match->pattern, relpath, pathlen) :
438-
!strncmp(match->pattern, relpath, pathlen));
439-
440-
if (prefixed && git_path_at_end_of_segment(&match->pattern[pathlen]))
441-
return true;
442-
}
443-
444432
return (p_fnmatch(match->pattern, filename, flags) != FNM_NOMATCH);
445433
}
446434

tests/attr/ignore.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,28 @@ void test_attr_ignore__case_sensitive_unignore_does_nothing(void)
372372

373373
assert_is_ignored(true, "case/file");
374374
}
375+
376+
void test_attr_ignore__ignored_subdirfiles_with_subdir_rule(void)
377+
{
378+
cl_git_rewritefile(
379+
"attr/.gitignore",
380+
"dir/*\n"
381+
"!dir/sub1/sub2/**\n");
382+
383+
assert_is_ignored(true, "dir/a.test");
384+
assert_is_ignored(true, "dir/sub1/a.test");
385+
assert_is_ignored(true, "dir/sub1/sub2");
386+
}
387+
388+
void test_attr_ignore__ignored_subdirfiles_with_negations(void)
389+
{
390+
cl_git_rewritefile(
391+
"attr/.gitignore",
392+
"dir/*\n"
393+
"!dir/a.test\n");
394+
395+
assert_is_ignored(false, "dir/a.test");
396+
assert_is_ignored(true, "dir/b.test");
397+
assert_is_ignored(true, "dir/sub1/c.test");
398+
}
399+

0 commit comments

Comments
 (0)