@@ -59,12 +59,14 @@ dependency should be removed entirely, downgrading or removing modules
5959depending on it as needed.
6060
6161The version suffix @latest explicitly requests the latest minor release of the
62- given path. The suffix @patch requests the latest patch release: if the path
63- is already in the build list, the selected version will have the same minor
64- version. If the path is not already in the build list, @patch is equivalent
65- to @latest. Neither @latest nor @patch will cause 'go get' to downgrade a module
66- in the build list if it is required at a newer pre-release version that is
67- newer than the latest released version.
62+ module named by the given path. The suffix @upgrade is like @latest but
63+ will not downgrade a module if it is already required at a revision or
64+ pre-release version newer than the latest released version. The suffix
65+ @patch requests the latest patch release: the latest released version
66+ with the same major and minor version numbers as the currently required
67+ version. Like @upgrade, @patch will not downgrade a module already required
68+ at a newer version. If the path is not already required, @upgrade and @patch
69+ are equivalent to @latest.
6870
6971Although get defaults to using the latest version of the module containing
7072a named package, it does not use the latest version of that module's
@@ -178,7 +180,7 @@ func (v *upgradeFlag) Set(s string) error {
178180 s = ""
179181 }
180182 if s == "true" {
181- s = "latest "
183+ s = "upgrade "
182184 }
183185 * v = upgradeFlag (s )
184186 return nil
@@ -202,8 +204,9 @@ type getArg struct {
202204 // if there is no "@"). path specifies the modules or packages to get.
203205 path string
204206
205- // vers is the part of the argument after "@" (or "" if there is no "@").
206- // vers specifies the module version to get.
207+ // vers is the part of the argument after "@" or an implied
208+ // "upgrade" or "patch" if there is no "@". vers specifies the
209+ // module version to get.
207210 vers string
208211}
209212
@@ -249,7 +252,7 @@ func runGet(cmd *base.Command, args []string) {
249252 }
250253
251254 switch getU {
252- case "" , "latest " , "patch" :
255+ case "" , "upgrade " , "patch" :
253256 // ok
254257 default :
255258 base .Fatalf ("go get: unknown upgrade flag -u=%s" , getU )
@@ -283,11 +286,11 @@ func runGet(cmd *base.Command, args []string) {
283286
284287 // Parse command-line arguments and report errors. The command-line
285288 // arguments are of the form path@version or simply path, with implicit
286- // @latest . path@none is "downgrade away".
289+ // @upgrade . path@none is "downgrade away".
287290 var gets []getArg
288291 var queries []* query
289292 for _ , arg := range search .CleanPatterns (args ) {
290- // Argument is module query path@vers, or else path with implicit @latest .
293+ // Argument is path or path@vers .
291294 path := arg
292295 vers := ""
293296 if i := strings .Index (arg , "@" ); i >= 0 {
@@ -298,10 +301,14 @@ func runGet(cmd *base.Command, args []string) {
298301 continue
299302 }
300303
301- // If the user runs 'go get -u=patch some/module', update some/module to a
302- // patch release, not a minor version.
303- if vers == "" && getU != "" {
304- vers = string (getU )
304+ // If no version suffix is specified, assume @upgrade.
305+ // If -u=patch was specified, assume @patch instead.
306+ if vers == "" {
307+ if getU != "" {
308+ vers = string (getU )
309+ } else {
310+ vers = "upgrade"
311+ }
305312 }
306313
307314 gets = append (gets , getArg {raw : arg , path : path , vers : vers })
@@ -358,7 +365,7 @@ func runGet(cmd *base.Command, args []string) {
358365 // The argument is a package path.
359366 if pkgs := modload .TargetPackages (path ); len (pkgs ) != 0 {
360367 // The path is in the main module. Nothing to query.
361- if vers != "" && vers != "latest " && vers != "patch" {
368+ if vers != "upgrade " && vers != "patch" {
362369 base .Errorf ("go get %s: can't request explicit version of path in main module" , arg )
363370 }
364371 continue
@@ -376,8 +383,8 @@ func runGet(cmd *base.Command, args []string) {
376383 continue
377384 }
378385
379- // If we're querying "latest " or "patch", we need to know the current
380- // version of the module. For "latest ", we want to avoid accidentally
386+ // If we're querying "upgrade " or "patch", we need to know the current
387+ // version of the module. For "upgrade ", we want to avoid accidentally
381388 // downgrading from a newer prerelease. For "patch", we need to query
382389 // the correct minor version.
383390 // Here, we check if "path" is the name of a module in the build list
@@ -736,10 +743,6 @@ func getQuery(path, vers string, prevM module.Version, forceModulePath bool) (mo
736743 base .Fatalf ("go get: internal error: prevM may be set if and only if forceModulePath is set" )
737744 }
738745
739- if vers == "" || vers == "patch" && prevM .Version == "" {
740- vers = "latest"
741- }
742-
743746 if forceModulePath || ! strings .Contains (path , "..." ) {
744747 if path == modload .Target .Path {
745748 if vers != "latest" {
@@ -893,9 +896,10 @@ func (u *upgrader) Upgrade(m module.Version) (module.Version, error) {
893896 // which may return a pseudoversion for the latest commit.
894897 // Query "latest" returns the newest tagged version or the newest
895898 // prerelease version if there are no non-prereleases, or repo.Latest
896- // if there aren't any tagged versions. Since we're providing the previous
897- // version, Query will confirm the latest version is actually newer
898- // and will return the current version if not.
899+ // if there aren't any tagged versions.
900+ // If we're querying "upgrade" or "patch", Query will compare the current
901+ // version against the chosen version and will return the current version
902+ // if it is newer.
899903 info , err := modload .Query (m .Path , string (getU ), m .Version , modload .Allowed )
900904 if err != nil {
901905 // Report error but return m, to let version selection continue.
0 commit comments