I was using go get -u
to get a package which depends on golang.org/x/[email protected]
. I noticed that it first downloads golang.org/x/[email protected]
then downloads golang.org/x/[email protected]
.
Then I ran go clean -modcache
and go get golang.org/x/text
which downloaded v0.4.0
of golang.org/x/text
and then again go get -u entgo.io/ent
. This time go didn't download golang.org/x/[email protected]
So, Why go get -u
downloads both the old version and latest version when the latest version is not present locally, and Why it doesn't download the old version when the latest version is available locally?
CodePudding user response:
Because it is a two-step process of
- Getting dependencies
- Updating dependencies
From a programming standpoint there is no good reason to merge these into a single concern of "Get latest dependencies".
From the go command documentation:
The -u flag instructs get to update modules providing dependencies of packages named on the command line to use newer minor or patch releases when available.
This means that -u
specifically deals with modules which the package you are getting depends on, rather than with the module of the package you are getting.
Furthermore, it appears that -u
is agnostic to the Go idiom of treating any change in a v0
version as a major version change, so one cannot lightheartedly recommend using -u
out of principle. The README of golang.org/x/test even says:
Until version 1.0.0 of x/text is reached, the minor version is considered a major version. So going from 0.1.0 to 0.2.0 is considered to be a major version bump.