Dep: Ignore source files from dep scanning [feature request]

Created on 30 Oct 2017  路  3Comments  路  Source: golang/dep

I have a project which contains some source files that should not be scanned by the dep tood because these are not part of the go packages I want to vendor. I would like to have an option (much like .gitignore) that makes it possible to ignore some files or directory.

In this particular case, it's an entire GOPATH embedded within the repository which contain checkout of other packages. This is only used by the build system to build other things and should not be read by dep.

Solutions include:

  • ignore patterns (the ignore option in Gopkg.toml doesn't seem to work). Either on Gopkg.toml or in .depignore files
  • options on thedep command line to select which pckages to vendor.

For example, go tools like go build can take command line arguments which selects which packages are build. go build . would only build the current directory without its subdirectories. go build ./... will build everything recursively.

An option to run dep ensure . to vendor only the current directory non recursively, or dep ensure . ./util/... ./handlers/... to vendor the current directory non recursively, and util and handlers recursively would be very nice.

To give an example, my current repository looks like:

  • main.go
  • util/

    • util.go

  • Gopkg.lock
  • Gopkg.toml
  • vendor/

    • ...

  • .git/

    • ...

  • bin/
  • pkg/
  • src/

    • github.com/hashicorp/terraform



      • (git submocule that contains the terraform checkout)



I want the vendor directory to contain only vendored dependencies from the root package (main.go) and the util sub-package (util/util.go) but not to vendor the entire src/github.com/hashicorp/terraform tree.

Most helpful comment

ignore patterns (the ignore option in Gopkg.toml doesn't seem to work). Either on Gopkg.toml or in .depignore files

If .gitignore is the model you have in your mind, then you're probably specifying relative import paths in ignored, e.g. src*. that isn't (and can't) be the way that behavior works - those ignores have to operate within the global namespace of import paths, not your local filesystem namespace. You'll need to specify it as an import path, and with the wildcard character - so, if your project lived at github.com/mildred/project, you'd need this:

ignored = ["github.com/mildred/project/src*"]

All 3 comments

ignore patterns (the ignore option in Gopkg.toml doesn't seem to work). Either on Gopkg.toml or in .depignore files

If .gitignore is the model you have in your mind, then you're probably specifying relative import paths in ignored, e.g. src*. that isn't (and can't) be the way that behavior works - those ignores have to operate within the global namespace of import paths, not your local filesystem namespace. You'll need to specify it as an import path, and with the wildcard character - so, if your project lived at github.com/mildred/project, you'd need this:

ignored = ["github.com/mildred/project/src*"]

Thank you, it can solve the problem. I was using an older version of dep that didn't support wildcards and now that wildcards are working, this may just be enough.

great! glad we can cover this for you.

Was this page helpful?
0 / 5 - 0 ratings