I was getting a compile error which led me to believe that I had the wrong version of a library in my vendor folder. The first task was to determine what revision of the library was correct. I needed to find the version of the library source that contained the string "VolumeCreateRequest". For that I used this trick from the root folder of the library:
git rev-list --all | xargs git grep VolumeCreateRequest
From that I found the version hash: 06f160237426e705ed214a4f087d4aeea32c0a8b
:
So then I tried to add that version into my vendor folder
go vendor add github.com/docker/docker/...@06f160237426e705ed214a4f087d4aeea32c0a8b
But it doesn't work. When I check the library's version using git it does not report the version I just fetched.
git log -n 1 --pretty=format:"%H"
The vendor.json file also contains the wrong version
so what's up? After carefully reading the docs I see go vender add just silently ignores the @06f160237426e705ed214a4f087d4aeea32c0a8b
on the end of my fetch URI.
The correct command is go vendor fetch which supports the @version
govendor fetch github.com/docker/docker/...@06f160237426e705ed214a4f087d4aeea32c0a8b
Another way to accomplish this is to git checkout the version you want of the library, in your GOPATH (i.e. not in your vendor folder), then govendor add
the package from your GOPATH
So now I check the git version and we are all good. Then the next problem occurred. Our generate.go file (invoked by go generate
) is going in and overwriting the desired version in my vendor.json
with what was on my GOPATH.
The sequence in our generate.go
is:
//go:generate govendor add +external
//go:generate govendor fetch +missing
//go:generate go vendor sync
This turned out to be wrong because the add would overwrite my changes, then the sync is ineffectual because vendor.json already infected with wrong version.
The correct sequence is this:
//go:generate govendor sync
//go:generate govendor add +external
//go:generate govendor fetch +missing
In this way, your customized vendor.json will sync the vendor folder to what is desired first, and only after that will external and missing dependencies be downloaded.
Finally, several dependencies actually would not compile at all do to platform specific stuff. To cure this, I add these lines in generate.go to remove those broken dependencies, after I sync, add, fetch
//go:generate govendor remove github.com/docker/docker/runconfig
//go:generate govendor remove github.com/docker/docker/libcontainerd
//go:generate govendor remove github.com/docker/libcompose/test
//go:generate govendor remove github.com/Microsoft/...