From 0b854dff9d23159f399da1e77d360b3d9be0c938 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Mon, 1 May 2017 16:58:08 +0000 Subject: [PATCH] lib/ignore: Don't match root (".") GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4122 --- lib/ignore/ignore.go | 2 +- lib/ignore/ignore_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/ignore/ignore.go b/lib/ignore/ignore.go index 20338ea9..e92cd7b2 100644 --- a/lib/ignore/ignore.go +++ b/lib/ignore/ignore.go @@ -163,7 +163,7 @@ func (m *Matcher) patternsUnchanged(file string) bool { } func (m *Matcher) Match(file string) (result Result) { - if m == nil { + if m == nil || file == "." { return resultNotMatched } diff --git a/lib/ignore/ignore_test.go b/lib/ignore/ignore_test.go index a3e5b0ef..e744e849 100644 --- a/lib/ignore/ignore_test.go +++ b/lib/ignore/ignore_test.go @@ -843,3 +843,32 @@ func TestIsInternal(t *testing.T) { } } } + +func TestRoot(t *testing.T) { + stignore := ` + !/a + /* + ` + + testcases := []struct { + file string + matches bool + }{ + {".", false}, + {"a", false}, + {"b", true}, + } + + pats := New(true) + err := pats.Parse(bytes.NewBufferString(stignore), ".stignore") + if err != nil { + t.Fatal(err) + } + + for _, tc := range testcases { + res := pats.Match(tc.file).IsIgnored() + if res != tc.matches { + t.Errorf("Matches(%q) == %v, expected %v", tc.file, res, tc.matches) + } + } +}