diff --git a/internal/ignore/doc.go b/internal/ignore/doc.go index a1f0fcfc8..ace0e8ef4 100644 --- a/internal/ignore/doc.go +++ b/internal/ignore/doc.go @@ -63,6 +63,6 @@ Notable differences from .gitignore: - The globbing library is Go's 'filepath.Match', not fnmatch(3) - Trailing spaces are always ignored (there is no supported escape sequence) - The evaluation of escape sequences has not been tested for compatibility - - There is no support for '\!' as a special leading sequence. + - There is no support for '\\!' as a special leading sequence for files that begin with `!` */ package ignore // import "helm.sh/helm/v3/internal/ignore" diff --git a/internal/ignore/rules.go b/internal/ignore/rules.go index a80923baf..731c429ec 100644 --- a/internal/ignore/rules.go +++ b/internal/ignore/rules.go @@ -102,30 +102,22 @@ func (r *Rules) Ignore(path string, fi os.FileInfo) bool { } for _, p := range r.patterns { if p.match == nil { - log.Printf("ignore: no matcher supplied for %q", p.raw) return false } - // For negative rules, we need to capture and return non-matches, - // and continue for matches. - if p.negate { - if p.mustDir && !fi.IsDir() { - return true - } - if !p.match(path, fi) { - return true - } - continue - } - // If the rule is looking for directories, and this is not a directory, // skip it. if p.mustDir && !fi.IsDir() { continue } + + // For negative rules, we need to capture and return non-matches, + // and continue for matches. if p.match(path, fi) { - return true + // if negate, then return false to "should I ignore" + return !p.negate } + } return false } diff --git a/internal/ignore/rules_test.go b/internal/ignore/rules_test.go index 9581cf09f..b1f071fed 100644 --- a/internal/ignore/rules_test.go +++ b/internal/ignore/rules_test.go @@ -113,10 +113,12 @@ func TestIgnore(t *testing.T) { {`helm.txt/`, "helm.txt", false}, // Negation tests - {`!helm.txt`, "helm.txt", false}, - {`!helm.txt`, "tiller.txt", true}, - {`!*.txt`, "cargo", true}, - {`!cargo/`, "mast/", true}, + {"!helm.txt\n*", "helm.txt", false}, + {"!helm.txt", "tiller.txt", false}, // Don't ignore files that match zero patterns + {"!helm.txt\n*", "tiller.txt", true}, + {"!*.txt\n*", "cargo", true}, + {"!cargo/\n*", "cargo", false}, + {"!cargo/\n*", "cargo/a.txt", true}, // Absolute path tests {`/a.txt`, "a.txt", true},