@@ -59,12 +59,14 @@ dependency should be removed entirely, downgrading or removing modules
59
59
depending on it as needed.
60
60
61
61
The 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.
68
70
69
71
Although get defaults to using the latest version of the module containing
70
72
a named package, it does not use the latest version of that module's
@@ -178,7 +180,7 @@ func (v *upgradeFlag) Set(s string) error {
178
180
s = ""
179
181
}
180
182
if s == "true" {
181
- s = "latest "
183
+ s = "upgrade "
182
184
}
183
185
* v = upgradeFlag (s )
184
186
return nil
@@ -202,8 +204,9 @@ type getArg struct {
202
204
// if there is no "@"). path specifies the modules or packages to get.
203
205
path string
204
206
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.
207
210
vers string
208
211
}
209
212
@@ -249,7 +252,7 @@ func runGet(cmd *base.Command, args []string) {
249
252
}
250
253
251
254
switch getU {
252
- case "" , "latest " , "patch" :
255
+ case "" , "upgrade " , "patch" :
253
256
// ok
254
257
default :
255
258
base .Fatalf ("go get: unknown upgrade flag -u=%s" , getU )
@@ -283,11 +286,11 @@ func runGet(cmd *base.Command, args []string) {
283
286
284
287
// Parse command-line arguments and report errors. The command-line
285
288
// 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".
287
290
var gets []getArg
288
291
var queries []* query
289
292
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 .
291
294
path := arg
292
295
vers := ""
293
296
if i := strings .Index (arg , "@" ); i >= 0 {
@@ -298,10 +301,14 @@ func runGet(cmd *base.Command, args []string) {
298
301
continue
299
302
}
300
303
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
+ }
305
312
}
306
313
307
314
gets = append (gets , getArg {raw : arg , path : path , vers : vers })
@@ -358,7 +365,7 @@ func runGet(cmd *base.Command, args []string) {
358
365
// The argument is a package path.
359
366
if pkgs := modload .TargetPackages (path ); len (pkgs ) != 0 {
360
367
// The path is in the main module. Nothing to query.
361
- if vers != "" && vers != "latest " && vers != "patch" {
368
+ if vers != "upgrade " && vers != "patch" {
362
369
base .Errorf ("go get %s: can't request explicit version of path in main module" , arg )
363
370
}
364
371
continue
@@ -376,8 +383,8 @@ func runGet(cmd *base.Command, args []string) {
376
383
continue
377
384
}
378
385
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
381
388
// downgrading from a newer prerelease. For "patch", we need to query
382
389
// the correct minor version.
383
390
// 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
736
743
base .Fatalf ("go get: internal error: prevM may be set if and only if forceModulePath is set" )
737
744
}
738
745
739
- if vers == "" || vers == "patch" && prevM .Version == "" {
740
- vers = "latest"
741
- }
742
-
743
746
if forceModulePath || ! strings .Contains (path , "..." ) {
744
747
if path == modload .Target .Path {
745
748
if vers != "latest" {
@@ -893,9 +896,10 @@ func (u *upgrader) Upgrade(m module.Version) (module.Version, error) {
893
896
// which may return a pseudoversion for the latest commit.
894
897
// Query "latest" returns the newest tagged version or the newest
895
898
// 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.
899
903
info , err := modload .Query (m .Path , string (getU ), m .Version , modload .Allowed )
900
904
if err != nil {
901
905
// Report error but return m, to let version selection continue.
0 commit comments