@@ -17,7 +17,6 @@ import (
1717 "cmd/go/internal/par"
1818 "cmd/go/internal/search"
1919 "cmd/go/internal/semver"
20- "cmd/go/internal/str"
2120 "cmd/go/internal/work"
2221 "errors"
2322 "fmt"
@@ -29,9 +28,9 @@ import (
2928)
3029
3130var CmdGet = & base.Command {
32- // Note: -d -m - u are listed explicitly because they are the most common get flags.
31+ // Note: -d -u are listed explicitly because they are the most common get flags.
3332 // Do not send CLs removing them because they're covered by [get flags].
34- UsageLine : "go get [-d] [-m] [- t] [-u] [-v] [-insecure] [build flags] [packages]" ,
33+ UsageLine : "go get [-d] [-t] [-u] [-v] [-insecure] [build flags] [packages]" ,
3534 Short : "add dependencies to current module and install them" ,
3635 Long : `
3736Get resolves and adds dependencies to the current development module
@@ -97,18 +96,6 @@ this automatically. Similarly, downgrading one dependency may
9796require downgrading other dependencies, and 'go get' does
9897this automatically as well.
9998
100- The -m flag instructs get to stop here, after resolving, upgrading,
101- and downgrading modules and updating go.mod. When using -m,
102- each specified package path must be a module path as well,
103- not the import path of a package below the module root.
104-
105- When the -m and -u flags are used together, 'go get' will upgrade
106- modules that provide packages depended on by the modules named on
107- the command line. For example, 'go get -u -m A' will upgrade A and
108- any module providing packages imported by packages in A.
109- 'go get -u -m' will upgrade modules that provided packages needed
110- by the main module.
111-
11299The -insecure flag permits fetching from repositories and resolving
113100custom domains using insecure schemes such as HTTP. Use with caution.
114101
@@ -227,8 +214,7 @@ type querySpec struct {
227214 // vers specifies what version of the module to get.
228215 vers string
229216
230- // forceModulePath is true if path should be interpreted as a module path
231- // even if -m is not specified.
217+ // forceModulePath is true if path should be interpreted as a module path.
232218 forceModulePath bool
233219
234220 // prevM is the previous version of the module. prevM is needed
@@ -267,6 +253,9 @@ func runGet(cmd *base.Command, args []string) {
267253 if * getFix {
268254 fmt .Fprintf (os .Stderr , "go get: -fix flag is a no-op when using modules\n " )
269255 }
256+ if * getM {
257+ base .Fatalf ("go get: -m flag is no longer supported" )
258+ }
270259 modload .LoadTests = * getT
271260
272261 if cfg .BuildMod == "vendor" {
@@ -318,12 +307,7 @@ func runGet(cmd *base.Command, args []string) {
318307 // contains no wildcards (...), check that it is a package in
319308 // the main module. If the path contains wildcards but matches no
320309 // packages, we'll warn after package loading.
321- if len (args ) > 0 && * getM {
322- base .Errorf ("go get %s: -m requires a module path, but a relative path must be a package in the main module" , arg )
323- continue
324- }
325-
326- if ! * getM && ! strings .Contains (path , "..." ) {
310+ if ! strings .Contains (path , "..." ) {
327311 pkgPath := modload .DirImportPath (filepath .FromSlash (path ))
328312 if pkgs := modload .TargetPackages (pkgPath ); len (pkgs ) == 0 {
329313 abs , err := filepath .Abs (path )
@@ -341,25 +325,7 @@ func runGet(cmd *base.Command, args []string) {
341325 }
342326
343327 case strings .Contains (path , "..." ):
344- // If we're using -m, look up modules in the build list that match
345- // the pattern. Report an error if no modules match.
346- if * getM {
347- match := search .MatchPattern (path )
348- matched := false
349- for _ , m := range modload .BuildList () {
350- if match (m .Path ) || str .HasPathPrefix (path , m .Path ) {
351- queries = append (queries , & query {querySpec : querySpec {path : m .Path , vers : vers , prevM : m , forceModulePath : true }, arg : arg })
352- matched = true
353- }
354- }
355- if ! matched {
356- base .Errorf ("go get %s: pattern matches no modules in build list" , arg )
357- continue
358- }
359- break
360- }
361-
362- // If we're not using -m, wait until we load packages to look up modules.
328+ // Wait until we load packages to look up modules.
363329 // We don't know yet whether any modules in the build list provide
364330 // packages matching the pattern. For example, suppose
365331 // golang.org/x/tools and golang.org/x/tools/playground are separate
@@ -369,34 +335,34 @@ func runGet(cmd *base.Command, args []string) {
369335 // upgrade golang.org/x/tools.
370336
371337 case path == "all" :
372- // This is the package pattern "all" not the module pattern "all",
373- // even if *getM. We won't create any queries yet, since we're going to
374- // need to load packages anyway.
338+ // Don't query modules until we load packages. We'll automatically
339+ // look up any missing modules.
375340
376341 case search .IsMetaPackage (path ):
377342 base .Errorf ("go get %s: explicit requirement on standard-library module %s not allowed" , path , path )
378343 continue
379344
380345 default :
381- // The argument is a package path or module path or both.
382- q := & query {querySpec : querySpec {path : path , vers : vers }, arg : arg }
383- if vers == "patch" {
384- if * getM {
385- for _ , m := range modload .BuildList () {
386- if m .Path == path {
387- q .prevM = m
388- break
389- }
390- }
391- queries = append (queries , q )
392- } else {
393- // We need to know the module containing path before asking for
394- // a specific version. Wait until we load packages later.
346+ // The argument is a package path.
347+ if pkgs := modload .TargetPackages (path ); len (pkgs ) != 0 {
348+ // The path is in the main module. Nothing to query.
349+ if vers != "" && vers != "latest" && vers != "patch" {
350+ base .Errorf ("go get %s: can't request explicit version of path in main module" , arg )
395351 }
352+ continue
353+ }
354+
355+ if vers == "patch" {
356+ // We need to know the previous version of the module to find
357+ // the new version, but we don't know what module provides this
358+ // package yet. Wait until we load packages later.
359+ // TODO(golang.org/issue/30634): @latest should also depend on
360+ // the current version to prevent downgrading from newer pseudoversions.
396361 } else {
397362 // The requested version of path doesn't depend on the existing version,
398- // so don't bother resolving it.
399- queries = append (queries , q )
363+ // so query the module before loading the package. This may let us
364+ // load the package only once at the correct version.
365+ queries = append (queries , & query {querySpec : querySpec {path : path , vers : vers }, arg : arg })
400366 }
401367 }
402368 }
@@ -430,7 +396,7 @@ func runGet(cmd *base.Command, args []string) {
430396 modOnly [q .m .Path ] = q
431397 continue
432398 }
433- if ! * getM && q .path == q .m .Path {
399+ if q .path == q .m .Path {
434400 wg .Add (1 )
435401 go func (q * query ) {
436402 if hasPkg , err := modload .ModuleHasRootPackage (q .m ); err != nil {
@@ -477,17 +443,13 @@ func runGet(cmd *base.Command, args []string) {
477443 // Don't load packages if pkgPatterns is empty. Both
478444 // modload.ImportPathsQuiet and ModulePackages convert an empty list
479445 // of patterns to []string{"."}, which is not what we want.
480- if * getM {
481- matches = modload .ModulePackages (pkgPatterns )
482- } else {
483- matches = modload .ImportPathsQuiet (pkgPatterns )
484- }
446+ matches = modload .ImportPathsQuiet (pkgPatterns )
485447 seenPkgs = make (map [string ]bool )
486448 install = make ([]string , 0 , len (pkgPatterns ))
487449 for i , match := range matches {
488450 arg := pkgGets [i ]
489451
490- if ! * getM && len (match .Pkgs ) == 0 {
452+ if len (match .Pkgs ) == 0 {
491453 // If the pattern did not match any packages, look up a new module.
492454 // If the pattern doesn't match anything on the last iteration,
493455 // we'll print a warning after the outer loop.
@@ -516,12 +478,8 @@ func runGet(cmd *base.Command, args []string) {
516478 allStd = false
517479 addQuery (& query {querySpec : querySpec {path : m .Path , vers : arg .vers , forceModulePath : true , prevM : m }, arg : arg .raw })
518480 }
519- if allStd {
520- if * getM {
521- base .Errorf ("go get %s: cannot use pattern %q with -m" , arg .raw , arg .raw )
522- } else if arg .path != arg .raw {
523- base .Errorf ("go get %s: cannot use pattern %q with explicit version" , arg .raw , arg .raw )
524- }
481+ if allStd && arg .path != arg .raw {
482+ base .Errorf ("go get %s: cannot use pattern %q with explicit version" , arg .raw , arg .raw )
525483 }
526484 }
527485 }
@@ -552,9 +510,7 @@ func runGet(cmd *base.Command, args []string) {
552510 }
553511 prevBuildList = buildList
554512 }
555- if ! * getM {
556- search .WarnUnmatched (matches ) // don't warn on every iteration
557- }
513+ search .WarnUnmatched (matches ) // don't warn on every iteration
558514
559515 // Handle downgrades.
560516 var down []module.Version
@@ -645,12 +601,14 @@ func runGet(cmd *base.Command, args []string) {
645601 modload .AllowWriteGoMod ()
646602 modload .WriteGoMod ()
647603
648- // If -m or -d was specified, we're done after the module work. We've
649- // already downloaded modules by loading packages above. If neither flag
650- // we specified, we need build and install the packages.
651- // Note that 'go get -u' without any arguments results in len(install) == 1:
652- // search.CleanImportPaths returns "." for empty args.
653- if * getM || * getD || len (install ) == 0 {
604+ // If -d was specified, we're done after the module work.
605+ // We've already downloaded modules by loading packages above.
606+ // Otherwise, we need to build and install the packages matched
607+ // by command line arguments.
608+ // Note that 'go get -u' without any arguments results in
609+ // len(install) == 1 if there's a package in the current directory.
610+ // search.CleanPatterns returns "." for empty args.
611+ if * getD || len (install ) == 0 {
654612 return
655613 }
656614 work .BuildInit ()
@@ -726,7 +684,7 @@ func getQuery(path, vers string, prevM module.Version, forceModulePath bool) (mo
726684 }
727685 }
728686
729- if forceModulePath || * getM || ! strings .Contains (path , "..." ) {
687+ if forceModulePath || ! strings .Contains (path , "..." ) {
730688 if path == modload .Target .Path {
731689 if vers != "latest" {
732690 return module.Version {}, fmt .Errorf ("can't get a specific version of the main module" )
@@ -740,7 +698,7 @@ func getQuery(path, vers string, prevM module.Version, forceModulePath bool) (mo
740698 }
741699
742700 // If the query fails, and the path must be a real module, report the query error.
743- if forceModulePath || * getM {
701+ if forceModulePath {
744702 return module.Version {}, err
745703 }
746704 }
0 commit comments