Fix ** matching

This commit is contained in:
Kovid Goyal 2025-07-08 10:02:43 +05:30
parent bde347457c
commit 4383398f25
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 22 additions and 1 deletions

View file

@ -65,7 +65,7 @@ func anchored_full_match(path string, parts []string) bool {
for pos <= last && path != "" {
var name string
name, path, _ = strings.Cut(path, "/")
switch name {
switch parts[pos] {
case "**":
for pos+1 < len(parts) && parts[pos+1] == "**" {
pos++
@ -73,6 +73,7 @@ func anchored_full_match(path string, parts []string) bool {
if pos == last {
return true
}
pos++
for {
matches, err := filepath.Match(parts[pos], name)
if err != nil {

View file

@ -65,6 +65,26 @@ func TestGitignore(t *testing.T) {
{"foo.*", []ptest{
{"foo.txt", true}, {"foo", false}, {"a/foo.x", true}, {"foo.", true},
}},
{"**", []ptest{
{"foo", true}, {"x/foo", true}, {"foo/x", true},
}},
{"**/foo", []ptest{
{"foo", true}, {"x/foo", true}, {"foo/x", false},
}},
{"**/foo/bar", []ptest{
{"foo", false}, {"x/foo", false}, {"foo/bar", true}, {"a/foo/bar", true}, {"foo/bar/a", false},
}},
{"foo/**", []ptest{
{"foo", false}, {"x/foo", false}, {"foo/bar", true}, {"foo/bar/a", true}, {"foo/bar/a/", true},
}},
{"a/**/b", []ptest{
{"a/b", true}, {"a/x/b", true}, {"a/x/y/b", true}, {"x/a/b", false}, {"a/b/x", false},
}},
{"a/**/b/**/c", []ptest{
{"a/b/c", true}, {"a/x/b/c", true}, {"a/x/y/b/m/n/c", true},
}},
} {
p, skipped := CompileGitIgnoreLine(x.line)
if skipped {