Skip to content

Commit 4de6eb5

Browse files
authored
Merge pull request libgit2#5074 from libgit2/ethomson/ignore_leading_slash
Ignore: only treat one leading slash as a root identifier
2 parents b1795e0 + e269b34 commit 4de6eb5

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/attr_file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,8 @@ int git_attr_fnmatch__parse(
622622
if (*scan == '/') {
623623
spec->flags = spec->flags | GIT_ATTR_FNMATCH_FULLPATH;
624624
slash_count++;
625-
if (pattern == scan)
625+
626+
if (slash_count == 1 && pattern == scan)
626627
pattern++;
627628
}
628629
/* remember if we see an unescaped wildcard in pattern */

tests/status/ignore.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,30 @@ void test_status_ignore__leading_slash_ignores(void)
413413
cl_assert_equal_i(0, counts.wrong_sorted_path);
414414
}
415415

416+
void test_status_ignore__multiple_leading_slash(void)
417+
{
418+
static const char *test_files[] = {
419+
"empty_standard_repo/a.test",
420+
"empty_standard_repo/b.test",
421+
"empty_standard_repo/c.test",
422+
"empty_standard_repo/d.test",
423+
NULL
424+
};
425+
426+
make_test_data("empty_standard_repo", test_files);
427+
cl_git_mkfile(
428+
"empty_standard_repo/.gitignore",
429+
"a.test\n"
430+
"/b.test\n"
431+
"//c.test\n"
432+
"///d.test\n");
433+
434+
assert_is_ignored("a.test");
435+
assert_is_ignored("b.test");
436+
refute_is_ignored("c.test");
437+
refute_is_ignored("d.test");
438+
}
439+
416440
void test_status_ignore__contained_dir_with_matching_name(void)
417441
{
418442
static const char *test_files[] = {

0 commit comments

Comments
 (0)