@@ -67,16 +67,11 @@ func (p Pattern) allowsSkippingIgnoredDirs() bool {
|
||||
if p.pattern[0] != '/' {
|
||||
return false
|
||||
}
|
||||
// Double asterisk everywhere in the path except at the end is bad
|
||||
if strings.Contains(strings.TrimSuffix(p.pattern, "**"), "**") {
|
||||
if strings.Contains(p.pattern[1:], "/") {
|
||||
return false
|
||||
}
|
||||
// Any wildcards anywhere except for the last path component are bad
|
||||
lastSep := strings.LastIndex(p.pattern, "/")
|
||||
if lastSep == -1 {
|
||||
return true
|
||||
}
|
||||
return p.pattern[:lastSep] == glob.QuoteMeta(p.pattern[:lastSep])
|
||||
// Double asterisk everywhere in the path except at the end is bad
|
||||
return !strings.Contains(strings.TrimSuffix(p.pattern, "**"), "**")
|
||||
}
|
||||
|
||||
type Result uint8
|
||||
|
||||
@@ -1110,10 +1110,10 @@ func TestSkipIgnoredDirs(t *testing.T) {
|
||||
{`!/t*t`, true},
|
||||
{`!/t?t`, true},
|
||||
{`!/**`, true},
|
||||
{`!/parent/test`, true},
|
||||
{`!/parent/t[eih]t`, true},
|
||||
{`!/parent/t*t`, true},
|
||||
{`!/parent/t?t`, true},
|
||||
{`!/parent/test`, false},
|
||||
{`!/parent/t[eih]t`, false},
|
||||
{`!/parent/t*t`, false},
|
||||
{`!/parent/t?t`, false},
|
||||
{`!/**.mp3`, false},
|
||||
{`!/pa*nt/test`, false},
|
||||
{`!/pa[sdf]nt/t[eih]t`, false},
|
||||
@@ -1150,6 +1150,17 @@ func TestSkipIgnoredDirs(t *testing.T) {
|
||||
if !pats.SkipIgnoredDirs() {
|
||||
t.Error("SkipIgnoredDirs should be true")
|
||||
}
|
||||
|
||||
stignore = `
|
||||
!/foo/ign*
|
||||
*
|
||||
`
|
||||
if err := pats.Parse(bytes.NewBufferString(stignore), ".stignore"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if pats.SkipIgnoredDirs() {
|
||||
t.Error("SkipIgnoredDirs should be false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyPatterns(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user