diff --git a/scanner/walk.go b/scanner/walk.go index 8cb18972..6008d22e 100644 --- a/scanner/walk.go +++ b/scanner/walk.go @@ -113,10 +113,10 @@ func loadIgnoreFile(ignFile, base string) []*regexp.Regexp { return nil } defer fd.Close() - return parseIgnoreFile(fd, base) + return parseIgnoreFile(fd, base, filepath.Dir(ignFile)) } -func parseIgnoreFile(fd io.Reader, base string) []*regexp.Regexp { +func parseIgnoreFile(fd io.Reader, base, dir string) []*regexp.Regexp { var exps []*regexp.Regexp scanner := bufio.NewScanner(fd) for scanner.Scan() { @@ -148,6 +148,14 @@ func parseIgnoreFile(fd io.Reader, base string) []*regexp.Regexp { continue } exps = append(exps, exp) + } else if strings.HasPrefix(line, "#include ") { + includeFile := filepath.Join(dir, strings.Replace(line, "#include ", "", 1)) + if _, err := os.Stat(includeFile); os.IsNotExist(err) { + l.Infoln("Could not open ignore include file", includeFile) + } else { + includes := loadIgnoreFile(includeFile, base) + exps = append(exps, includes...) + } } else { // Path name or pattern, add it so it matches files both in // current directory and subdirs. diff --git a/scanner/walk_test.go b/scanner/walk_test.go index 943843b2..a0ac451e 100644 --- a/scanner/walk_test.go +++ b/scanner/walk_test.go @@ -128,20 +128,20 @@ func TestIgnore(t *testing.T) { */other/test **/deep `) - patterns := parseIgnoreFile(patStr, "") + patterns := parseIgnoreFile(patStr, "", "") patStr = bytes.NewBufferString(` bar z* q[abc]x `) - patterns = append(patterns, parseIgnoreFile(patStr, "foo")...) + patterns = append(patterns, parseIgnoreFile(patStr, "foo", "")...) patStr = bytes.NewBufferString(` quux .* `) - patterns = append(patterns, parseIgnoreFile(patStr, "foo/baz")...) + patterns = append(patterns, parseIgnoreFile(patStr, "foo/baz", "")...) var tests = []struct { f string