diff --git a/lib/ignore/ignore.go b/lib/ignore/ignore.go index e83e888f5..31f70e74a 100644 --- a/lib/ignore/ignore.go +++ b/lib/ignore/ignore.go @@ -279,14 +279,14 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([] var err error if strings.HasPrefix(line, "/") { // Pattern is rooted in the current dir only - pattern.match, err = glob.Compile(line[1:]) + pattern.match, err = glob.Compile(line[1:], '/') if err != nil { return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err) } patterns = append(patterns, pattern) } else if strings.HasPrefix(line, "**/") { // Add the pattern as is, and without **/ so it matches in current dir - pattern.match, err = glob.Compile(line) + pattern.match, err = glob.Compile(line, '/') if err != nil { return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err) } @@ -294,7 +294,7 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([] line = line[3:] pattern.pattern = line - pattern.match, err = glob.Compile(line) + pattern.match, err = glob.Compile(line, '/') if err != nil { return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err) } @@ -310,7 +310,7 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([] } else { // Path name or pattern, add it so it matches files both in // current directory and subdirs. - pattern.match, err = glob.Compile(line) + pattern.match, err = glob.Compile(line, '/') if err != nil { return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err) } @@ -318,7 +318,7 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([] line := "**/" + line pattern.pattern = line - pattern.match, err = glob.Compile(line) + pattern.match, err = glob.Compile(line, '/') if err != nil { return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err) } diff --git a/lib/ignore/ignore_test.go b/lib/ignore/ignore_test.go index 1439262e7..db59999a0 100644 --- a/lib/ignore/ignore_test.go +++ b/lib/ignore/ignore_test.go @@ -737,3 +737,35 @@ func TestIssue3639(t *testing.T) { t.Error("Should not match 'foo'") } } + +func TestIssue3674(t *testing.T) { + stignore := ` + a*b + a**c + ` + + testcases := []struct { + file string + matches bool + }{ + {"ab", true}, + {"asdfb", true}, + {"ac", true}, + {"asdfc", true}, + {"as/db", false}, + {"as/dc", 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) + } + } +}