I am trying to figure out how can I make sure I only vendor a particular package from a huge repository my project depends on.
For example consider this simple program with main.go and nothing else:
package main
import "google.golang.org/api/cloudbuild/v1"
func main() {
_ = v1.CloudPlatformScope
}
I then run dep init on this directory to initialize Gopkg files. This simple dependency yields in 2,129,065 lines of code to be vendored. Is this by design?
If I use govendor/godep this is not the case as those tools can figure out what packages are used in the build and vendor only those. Am I doing something wrong?
I just discovered the dep prune command which seems to be doing what I want. This made me wonder why is this not the default behavior?
I've recently sorta relented on this and have accepted as a TODO making pruning the default. But this whole area gets sticky and complicated if we want to make it _safe_ (which is our primary goal), and is the topic of #120 đ
(Closing as dup)
@ahmetb I have small make target dep, which makes sure most trash is cleaned :)
.PHONY: dep
dep: $(GOPATH)/bin/dep
dep ensure && dep prune && find ./vendor -name '*_test.go' -delete
$(GOPATH)/bin/dep:
go get -u github.com/golang/dep/cmd/dep
I'm using .gitignore to avoid unnecessary files in vendor/ directory:
# Ignore everything in vendor/, except for *.go files,
# LICENSE and COPYING. Ignore Go tests.
vendor/**
!vendor/**/*.go
!vendor/**/LICENSE
!vendor/**/COPYING
vendor/**/*_test.go
The gitignore snippet from @VojtechVitek wouldn't work in my case - and probably most cases - because the first line will ignore all directories under vendor, and per Git documentation
It is not possible to re-include a file if a parent directory of that file is excluded. Git doesnât list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.
(Spent some time figuring out why wouldn't Git see _anything_ inside my vendor directory.)
the gitignore approach is long since outdated, thanks to pruning.
Pruning doesnât remove non-Go files and test files. Which I think is correct, but I prefer removing them.
For reference, this is the âconversionâ of the .gitignore above into a shell script.
find vendor -type f -not -name "*.go" -not -name "LICENSE" -not -name "COPYING" -or -name "*_test.go" | xargs rm -f
Pruning doesnât remove non-Go files and test files.
'non-go' and 'go-tests' are two of the three types of pruning supported by dep: https://golang.github.io/dep/docs/Gopkg.toml.html#prune
sounds like you're on an old version. see the release announcement: https://golang.github.io/dep/blog/2018/01/23/announce-v0.4.0.html
On February 7, 2018 12:02:00 PM EST, Leonid Shevtsov notifications@github.com wrote:
Pruning doesnât remove non-Go files and test files. Which I think is
correct, but I prefer removing them.For reference, this is the âconversionâ of the .gitignore above into a
shell script.find vendor -type f -not -name "*.go" -not -name "LICENSE" -not -name "COPYING" -or -name "*_test.go" | xargs rm -f--
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub:
https://github.com/golang/dep/issues/625#issuecomment-363837301
@jmank88 @sdboyer indeed I was! Thanks for the clarification - very happy to see this feature.
Most helpful comment
I'm using .gitignore to avoid unnecessary files in vendor/ directory: