When vendor dir is part complete, dep ensure doesn't add missing dependencies #883
Description
What version of Go (go version
) and dep
(git describe --tags
) are you using?
root@d617216ea384:/go/src/vendtest# go version
go version go1.8.3 linux/amd64
root@d617216ea384:/go/src/github.com/golang/dep# git describe --tags
v0.1.0-282-g167adc2
What dep
command did you run?
docker run -it --rm golang:1.8 bash
root@3650b93883fb:/go# go get -u github.com/golang/dep/cmd/dep
root@3650b93883fb:/go# mkdir src/vendtest && cd src/vendtest
root@3650b93883fb:/go/src/vendtest# cat > main.go <<EOF
package main
import "github.com/pkg/errors"
func main() {
println(errors.New("foo error"))
}
EOF
root@fccf383a79f9:/go/src/vendtest# go run main.go
main.go:3:8: cannot find package "github.com/pkg/errors" in any of:
/usr/local/go/src/github.com/pkg/errors (from $GOROOT)
/go/src/github.com/pkg/errors (from $GOPATH)
root@3650b93883fb:/go/src/vendtest# dep init
Using ^0.8.0 as constraint for direct dep github.com/pkg/errors
Locking in v0.8.0 (645ef00) for direct dep github.com/pkg/errors
root@fccf383a79f9:/go/src/vendtest# go run main.go
(0x4e5140,0xc42000a160)
root@3650b93883fb:/go/src/vendtest# ls vendor/github.com/
pkg
So far so good, we've proven the dependency github.com/pkg/errors
didn't initially exist, running dep init
then added the dependency successfully and the program compiles.
The next step is a part of my workflow to switch between a vendored dependency, to that in my GOPATH, so I can iterate on a fork. This part isn't important (but appears to be the recommend workflow based on https://github.com/golang/dep/blob/master/README.md#testing-changes-to-a-dependency), just the fact that I've manually removed the dependency from the vendor dir.
root@3650b93883fb:/go/src/vendtest# rm -rf vendor/github.com/pkg
root@fccf383a79f9:/go/src/vendtest# go run main.go
main.go:3:8: cannot find package "github.com/pkg/errors" in any of:
/go/src/vendtest/vendor/github.com/pkg/errors (vendor tree)
/usr/local/go/src/github.com/pkg/errors (from $GOROOT)
/go/src/github.com/pkg/errors (from $GOPATH)
This non-compilation behaviour is expected, the dependency has been removed. Now I want to add it back:
root@3650b93883fb:/go/src/vendtest# dep ensure
root@fccf383a79f9:/go/src/vendtest# go run main.go
main.go:3:8: cannot find package "github.com/pkg/errors" in any of:
/go/src/vendtest/vendor/github.com/pkg/errors (vendor tree)
/usr/local/go/src/github.com/pkg/errors (from $GOROOT)
/go/src/github.com/pkg/errors (from $GOPATH)
root@fccf383a79f9:/go/src/vendtest# find .
.
./Gopkg.lock
./main.go
./Gopkg.toml
./vendor
./vendor/github.com
After running dep ensure
the dependency wasn't added! I don't expect this. I expected the dependency to be added to ./vendor/github.com/pkg/errors
.
But if I have an empty vendor directory, it works fine:
root@fccf383a79f9:/go/src/vendtest# rm -rf vendor/github.com
root@fccf383a79f9:/go/src/vendtest# dep ensure
root@fccf383a79f9:/go/src/vendtest# go run main.go
(0x4e5140,0xc42005c080)
What did you expect to see?
I expect dep
to add missing dependencies to the vendor folder, even if the vendor folder is not empty. If this is not possible, I'd then expect some warning from dep ensure
or dep status
, but there are no errors or warnings.
What did you see instead?
I saw no errors or warnings, and I saw the vendor folder didn't get populated with the dependency.
Note, I've searched the issues and couldn't find an existing case, sorry if this a dupe or won't fix. There's been another case of this discussed in #vendor in Gophers Slack https://gophers.slack.com/archives/C0M5YP9LN/p1500757752167225. I was able to reproduce this back when we switched from json to toml file formats, so I believe it's been occurring for a while (but I only checked this briefly, I may have been wrong).
Thanks all, I've been using dep
successfully for some time now, so cheers for the good work.