modPrefix = mod.Path
}
if mi, err := modindex.GetModule(root); err == nil {
- walkFromIndex(mi, modPrefix, isMatch, treeCanMatch, tags, have, addPkg)
+ walkFromIndex(mi, modPrefix, isMatch, treeCanMatch, tags, have, addPkg, ignorePatternsMap[root], root)
continue
} else if !errors.Is(err, modindex.ErrNotIndexed) {
m.AddError(err)
// walkFromIndex matches packages in a module using the module index. modroot
// is the module's root directory on disk, index is the modindex.Module for the
// module, and importPathRoot is the module's path prefix.
-func walkFromIndex(index *modindex.Module, importPathRoot string, isMatch, treeCanMatch func(string) bool, tags, have map[string]bool, addPkg func(string)) {
+func walkFromIndex(index *modindex.Module, importPathRoot string, isMatch, treeCanMatch func(string) bool, tags, have map[string]bool, addPkg func(string), ignorePatterns *search.IgnorePatterns, modRoot string) {
index.Walk(func(reldir string) {
// Avoid .foo, _foo, and testdata subdirectory trees.
p := reldir
p = rest
}
+ if ignorePatterns != nil && ignorePatterns.ShouldIgnore(reldir) {
+ if cfg.BuildX {
+ absPath := filepath.Join(modRoot, reldir)
+ fmt.Fprintf(os.Stderr, "# ignoring directory %s\n", absPath)
+ }
+ return
+ }
+
// Don't use GOROOT/src.
if reldir == "" && importPathRoot == "" {
return
--- /dev/null
+# go list should skip 'ignore' directives for indexed modules in the module cache
+# See golang.org/issue/42965
+
+env GOMODCACHE=$WORK${/}modcache
+go get example.com/ignore/...@v1.0.0
+go list -x example.com/ignore/...
+stderr 'ignoring directory '$GOMODCACHE''${/}'example.com'${/}'ignore@v1.0.0'${/}'foo'
+
+-- go.mod --
+module example
+
+go 1.24
+
+-- main.go --
+package main
+
+func main() {}
\ No newline at end of file