Merge pull request #5074 from libgit2/ethomson/ignore_leading_slash Ignore: only treat one leading slash as a root identifier
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 43 44 45 46 47 48 49
diff --git a/src/attr_file.c b/src/attr_file.c
index aef3e64..51ecfbb 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -622,7 +622,8 @@ int git_attr_fnmatch__parse(
if (*scan == '/') {
spec->flags = spec->flags | GIT_ATTR_FNMATCH_FULLPATH;
slash_count++;
- if (pattern == scan)
+
+ if (slash_count == 1 && pattern == scan)
pattern++;
}
/* remember if we see an unescaped wildcard in pattern */
diff --git a/tests/status/ignore.c b/tests/status/ignore.c
index c43f314..a93ff8b 100644
--- a/tests/status/ignore.c
+++ b/tests/status/ignore.c
@@ -413,6 +413,30 @@ void test_status_ignore__leading_slash_ignores(void)
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
+void test_status_ignore__multiple_leading_slash(void)
+{
+ static const char *test_files[] = {
+ "empty_standard_repo/a.test",
+ "empty_standard_repo/b.test",
+ "empty_standard_repo/c.test",
+ "empty_standard_repo/d.test",
+ NULL
+ };
+
+ make_test_data("empty_standard_repo", test_files);
+ cl_git_mkfile(
+ "empty_standard_repo/.gitignore",
+ "a.test\n"
+ "/b.test\n"
+ "//c.test\n"
+ "///d.test\n");
+
+ assert_is_ignored("a.test");
+ assert_is_ignored("b.test");
+ refute_is_ignored("c.test");
+ refute_is_ignored("d.test");
+}
+
void test_status_ignore__contained_dir_with_matching_name(void)
{
static const char *test_files[] = {