From fe9c2b98577f1a871ef0ecd4d7baa79482d046aa Mon Sep 17 00:00:00 2001 From: Tim Howes Date: Tue, 4 Oct 2016 08:12:55 +0900 Subject: [PATCH] lib/ignore: Match directory contents for patterns ending in / (fixes #3639) Appends "**" to patterns with a terminal slash, so that directory contents are ignored, but not the directory itself. --- lib/ignore/ignore.go | 2 +- lib/ignore/ignore_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/ignore/ignore.go b/lib/ignore/ignore.go index 0c269fae..e83e888f 100644 --- a/lib/ignore/ignore.go +++ b/lib/ignore/ignore.go @@ -345,7 +345,7 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([] case strings.HasSuffix(line, "/**"): err = addPattern(line) case strings.HasSuffix(line, "/"): - err = addPattern(line) + err = addPattern(line + "**") default: err = addPattern(line) if err == nil { diff --git a/lib/ignore/ignore_test.go b/lib/ignore/ignore_test.go index bad9be6f..1439262e 100644 --- a/lib/ignore/ignore_test.go +++ b/lib/ignore/ignore_test.go @@ -718,3 +718,22 @@ func TestIssue3174(t *testing.T) { t.Error("Should match") } } + +func TestIssue3639(t *testing.T) { + stignore := ` + foo/ + ` + pats := New(true) + err := pats.Parse(bytes.NewBufferString(stignore), ".stignore") + if err != nil { + t.Fatal(err) + } + + if !pats.Match("foo/bar").IsIgnored() { + t.Error("Should match 'foo/bar'") + } + + if pats.Match("foo").IsIgnored() { + t.Error("Should not match 'foo'") + } +}