lib/ignore: Keep skipping ignored dirs for rooted patterns (#6151)

* lib/ignore: Keep skipping ignored dirs for rooted patterns

* review

* clarify comment and lint

* glob.QuoteMeta

* review
This commit is contained in:
Simon Frei
2019-11-26 08:37:41 +01:00
committed by Audrius Butkevicius
parent 33258b06f4
commit f747ba6d69
3 changed files with 212 additions and 76 deletions

View File

@@ -1098,3 +1098,55 @@ func TestPartialIncludeLine(t *testing.T) {
}
}
}
func TestSkipIgnoredDirs(t *testing.T) {
tcs := []struct {
pattern string
expected bool
}{
{`!/test`, true},
{`!/t[eih]t`, true},
{`!/t*t`, true},
{`!/t?t`, true},
{`!/**`, true},
{`!/parent/test`, true},
{`!/parent/t[eih]t`, true},
{`!/parent/t*t`, true},
{`!/parent/t?t`, true},
{`!/**.mp3`, false},
{`!/pa*nt/test`, false},
{`!/pa[sdf]nt/t[eih]t`, false},
{`!/lowest/pa[sdf]nt/test`, false},
{`!/lo*st/parent/test`, false},
{`/pa*nt/test`, true},
{`test`, true},
{`*`, true},
}
for _, tc := range tcs {
pats, err := parseLine(tc.pattern)
if err != nil {
t.Error(err)
}
for _, pat := range pats {
if got := pat.allowsSkippingIgnoredDirs(); got != tc.expected {
t.Errorf(`Pattern "%v": got %v, expected %v`, pat, got, tc.expected)
}
}
}
pats := New(fs.NewFilesystem(fs.FilesystemTypeBasic, "testdata"), WithCache(true))
stignore := `
/foo/ign*
!/f*
!/bar
*
`
if err := pats.Parse(bytes.NewBufferString(stignore), ".stignore"); err != nil {
t.Fatal(err)
}
if !pats.SkipIgnoredDirs() {
t.Error("SkipIgnoredDirs should be true")
}
}