Skip to content

Commit e07dbc9

Browse files
authored
Merge pull request libgit2#5173 from pks-t/pks/gitignore-wildmatch-error
ignore: fix determining whether a shorter pattern negates another
2 parents fd7a384 + 6f6340a commit e07dbc9

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/ignore.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,8 @@ 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 ((error = wildmatch(git_buf_cstr(&buf), path, wildmatch_flags)) < 0) {
145-
git_error_set(GIT_ERROR_INVALID, "error matching pattern");
146-
goto out;
147-
}
148-
149144
/* if we found a match, we want to keep this rule */
150-
if (error != WM_NOMATCH) {
145+
if ((wildmatch(git_buf_cstr(&buf), path, wildmatch_flags)) == WM_MATCH) {
151146
*out = 1;
152147
error = 0;
153148
goto out;

tests/ignore/path.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,3 +560,18 @@ void test_ignore_path__escaped_space(void)
560560
assert_is_ignored(false, "bar\\\\\\");
561561
assert_is_ignored(false, "bar\\\\\\ ");
562562
}
563+
564+
void test_ignore_path__invalid_pattern(void)
565+
{
566+
cl_git_rewritefile("attr/.gitignore", "[");
567+
assert_is_ignored(false, "[f");
568+
assert_is_ignored(false, "f");
569+
}
570+
571+
void test_ignore_path__negative_prefix_rule(void)
572+
{
573+
cl_git_rewritefile("attr/.gitignore", "ff*\n!f\n");
574+
assert_is_ignored(true, "fff");
575+
assert_is_ignored(true, "ff");
576+
assert_is_ignored(false, "f");
577+
}

0 commit comments

Comments
 (0)