Merge pull request #2320 from libgit2/rb/fix-starstar-again Make ** pattern eat trailing slash
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
diff --git a/src/fnmatch.c b/src/fnmatch.c
index 3846bab..d8a83a8 100644
--- a/src/fnmatch.c
+++ b/src/fnmatch.c
@@ -62,6 +62,8 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs)
flags &= ~FNM_PATHNAME;
while (c == '*')
c = *++pattern;
+ if (c == '/')
+ c = *++pattern;
}
if (*string == '.' && (flags & FNM_PERIOD) &&
diff --git a/tests/attr/ignore.c b/tests/attr/ignore.c
index 6887519..5eadc7b 100644
--- a/tests/attr/ignore.c
+++ b/tests/attr/ignore.c
@@ -81,6 +81,24 @@ void test_attr_ignore__full_paths(void)
assert_is_ignored(false, "Folder/Middle/More/More/Contained/Not/Happy/Child");
}
+void test_attr_ignore__more_starstar_cases(void)
+{
+ cl_must_pass(p_unlink("attr/.gitignore"));
+ cl_git_mkfile(
+ "attr/dir/.gitignore",
+ "sub/**/*.html\n");
+
+ assert_is_ignored(false, "aaa.html");
+ assert_is_ignored(false, "dir");
+ assert_is_ignored(false, "dir/sub");
+ assert_is_ignored(true, "dir/sub/sub2/aaa.html");
+ assert_is_ignored(true, "dir/sub/aaa.html");
+ assert_is_ignored(false, "dir/aaa.html");
+ assert_is_ignored(false, "sub");
+ assert_is_ignored(false, "sub/aaa.html");
+ assert_is_ignored(false, "sub/sub2/aaa.html");
+}
+
void test_attr_ignore__leading_stars(void)
{
cl_git_rewritefile(