Backend: Refactor .ppignore pattern matching

Signed-off-by: Michael Mayer <michael@lastzero.net>
This commit is contained in:
Michael Mayer 2020-10-19 09:23:09 +02:00
parent 9eef7b37ab
commit c8ded4c7c1
11 changed files with 21 additions and 4 deletions

View file

@ -15,9 +15,10 @@ func TestDirs(t *testing.T) {
t.Fatal(err)
}
assert.Len(t, result, 7)
assert.Len(t, result, 8)
assert.Contains(t, result, "/directory")
assert.Contains(t, result, "/directory/subdirectory")
assert.Contains(t, result, "/directory/subdirectory/animals")
assert.Contains(t, result, "/linked")
})
@ -30,6 +31,7 @@ func TestDirs(t *testing.T) {
assert.Contains(t, result, "/directory")
assert.Contains(t, result, "/directory/subdirectory")
assert.Contains(t, result, "/directory/subdirectory/animals")
assert.Contains(t, result, "/linked")
})

View file

@ -34,8 +34,8 @@ func (i IgnoreItem) Ignore(dir, base string) bool {
return true
}
if ignore, err := filepath.Match(i.Pattern, filepath.Join(dir, base)); ignore && err == nil {
return true
if strings.ContainsRune(i.Pattern, filepath.Separator) {
base = filepath.Join(RelName(dir, i.Dir), base)
}
if ignore, err := filepath.Match(i.Pattern, base); ignore && err == nil {

View file

@ -94,6 +94,9 @@ func TestIgnoreList_Ignored(t *testing.T) {
expectIgnored := []string{
"testdata/directory/bar.txt",
"testdata/directory/baz.xml",
"testdata/directory/subdirectory/animals/dog.json",
"testdata/directory/subdirectory/animals/gopher.json",
"testdata/directory/subdirectory/animals/gopher.md",
"testdata/directory/subdirectory/bar",
"testdata/directory/subdirectory/example.txt",
"testdata/directory/subdirectory/foo.txt",

View file

@ -1,7 +1,7 @@
subdirectory/animals/dog.*
*.txt
test.md
# This is a comment
somefile.*
baz*
bar

View file

@ -0,0 +1 @@
bar

View file

@ -0,0 +1 @@
gopher*

View file

@ -0,0 +1 @@
{"name":"cat"}

View file

@ -0,0 +1 @@
{"name":"dog"}

View file

@ -0,0 +1 @@
{"name":"gopher"}

View file

@ -0,0 +1 @@
# Gopher!

View file

@ -97,6 +97,12 @@ func TestSkipWalk(t *testing.T) {
"testdata/directory/baz.xml",
"testdata/directory/subdirectory",
"testdata/directory/subdirectory/.hiddenfile",
"testdata/directory/subdirectory/.ppignore",
"testdata/directory/subdirectory/animals",
"testdata/directory/subdirectory/animals/.ppignore",
"testdata/directory/subdirectory/animals/dog.json",
"testdata/directory/subdirectory/animals/gopher.json",
"testdata/directory/subdirectory/animals/gopher.md",
"testdata/directory/subdirectory/example.txt",
"testdata/directory/subdirectory/foo.txt",
"testdata/directory/subdirectory/symlink",