aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/get/get.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2018-07-11 23:55:39 -0400
committerRuss Cox <rsc@golang.org>2018-07-12 20:46:50 +0000
commitf7248f05946c1804b5519d0b3eb0db054dc9c5d6 (patch)
tree73a9d64a6af33d4feefa5f3acf6eb7f7206a8a95 /src/cmd/go/internal/get/get.go
parentf22dd66b23ec1a703a3984cad1840bc8692cf1d0 (diff)
downloadgo-f7248f05946c1804b5519d0b3eb0db054dc9c5d6.tar.gz
go-f7248f05946c1804b5519d0b3eb0db054dc9c5d6.zip
cmd/go: merge module support from x/vgo repo
This CL corresponds to CL 123361, the final manual CL in that repo, making this the final manual sync. All future commits will happen in this repo (the main Go repo), and we'll update x/vgo automatically with a fixed patch+script. Change-Id: I572243309c1809727604fd704705a23c30e85d1a Reviewed-on: https://go-review.googlesource.com/123576 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/get/get.go')
-rw-r--r--src/cmd/go/internal/get/get.go67
1 files changed, 48 insertions, 19 deletions
diff --git a/src/cmd/go/internal/get/get.go b/src/cmd/go/internal/get/get.go
index 6eabc4eabb..36aa171c7f 100644
--- a/src/cmd/go/internal/get/get.go
+++ b/src/cmd/go/internal/get/get.go
@@ -18,13 +18,12 @@ import (
"cmd/go/internal/load"
"cmd/go/internal/search"
"cmd/go/internal/str"
- "cmd/go/internal/vgo"
"cmd/go/internal/web"
"cmd/go/internal/work"
)
var CmdGet = &base.Command{
- UsageLine: "get [-d] [-f] [-fix] [-insecure] [-t] [-u] [-v] [build flags] [packages]",
+ UsageLine: "get [-d] [-f] [-t] [-u] [-v] [-fix] [-insecure] [build flags] [packages]",
Short: "download and install packages and dependencies",
Long: `
Get downloads the packages named by the import paths, along with their
@@ -75,25 +74,49 @@ For more about specifying packages, see 'go help packages'.
For more about how 'go get' finds source code to
download, see 'go help importpath'.
+This text describes the behavior of get when using GOPATH
+to manage source code and dependencies.
+If instead the go command is running in module-aware mode,
+the details of get's flags and effects change, as does 'go help get'.
+See 'go help modules' and 'go help module-get'.
+
See also: go build, go install, go clean.
`,
}
-var getD = CmdGet.Flag.Bool("d", false, "")
-var getF = CmdGet.Flag.Bool("f", false, "")
-var getT = CmdGet.Flag.Bool("t", false, "")
-var getU = CmdGet.Flag.Bool("u", false, "")
-var getFix = CmdGet.Flag.Bool("fix", false, "")
-var getInsecure = CmdGet.Flag.Bool("insecure", false, "")
+var HelpGopathGet = &base.Command{
+ UsageLine: "gopath-get",
+ Short: "legacy GOPATH go get",
+ Long: `
+The 'go get' command changes behavior depending on whether the
+go command is running in module-aware mode or legacy GOPATH mode.
+This help text, accessible as 'go help gopath-get' even in module-aware mode,
+describes 'go get' as it operates in legacy GOPATH mode.
+
+Usage: ` + CmdGet.UsageLine + `
+` + CmdGet.Long,
+}
+
+var (
+ getD = CmdGet.Flag.Bool("d", false, "")
+ getF = CmdGet.Flag.Bool("f", false, "")
+ getT = CmdGet.Flag.Bool("t", false, "")
+ getU = CmdGet.Flag.Bool("u", false, "")
+ getFix = CmdGet.Flag.Bool("fix", false, "")
+
+ Insecure bool
+)
func init() {
work.AddBuildFlags(CmdGet)
CmdGet.Run = runGet // break init loop
+ CmdGet.Flag.BoolVar(&Insecure, "insecure", Insecure, "")
}
func runGet(cmd *base.Command, args []string) {
- if vgo.Enabled() {
- base.Fatalf("go get: vgo not implemented")
+ if cfg.ModulesEnabled {
+ // Should not happen: main.go should install the separate module-enabled get code.
+ base.Fatalf("go get: modules not implemented")
}
work.BuildInit()
@@ -167,7 +190,7 @@ func runGet(cmd *base.Command, args []string) {
return
}
- work.InstallPackages(args, true)
+ work.InstallPackages(args)
}
// downloadPaths prepares the list of paths to pass to download.
@@ -176,6 +199,12 @@ func runGet(cmd *base.Command, args []string) {
// in the hope that we can figure out the repository from the
// initial ...-free prefix.
func downloadPaths(args []string) []string {
+ for _, arg := range args {
+ if strings.Contains(arg, "@") {
+ base.Fatalf("go: cannot use path@version syntax in GOPATH mode")
+ }
+ }
+
args = load.ImportPathsForGoGet(args)
var out []string
for _, a := range args {
@@ -379,7 +408,7 @@ func downloadPackage(p *load.Package) error {
)
security := web.Secure
- if *getInsecure {
+ if Insecure {
security = web.Insecure
}
@@ -402,16 +431,16 @@ func downloadPackage(p *load.Package) error {
}
repo = remote
if !*getF && err == nil {
- if rr, err := repoRootForImportPath(p.ImportPath, security); err == nil {
- repo := rr.repo
+ if rr, err := RepoRootForImportPath(p.ImportPath, IgnoreMod, security); err == nil {
+ repo := rr.Repo
if rr.vcs.resolveRepo != nil {
resolved, err := rr.vcs.resolveRepo(rr.vcs, dir, repo)
if err == nil {
repo = resolved
}
}
- if remote != repo && rr.isCustom {
- return fmt.Errorf("%s is a custom import path for %s, but %s is checked out from %s", rr.root, repo, dir, remote)
+ if remote != repo && rr.IsCustom {
+ return fmt.Errorf("%s is a custom import path for %s, but %s is checked out from %s", rr.Root, repo, dir, remote)
}
}
}
@@ -419,13 +448,13 @@ func downloadPackage(p *load.Package) error {
} else {
// Analyze the import path to determine the version control system,
// repository, and the import path for the root of the repository.
- rr, err := repoRootForImportPath(p.ImportPath, security)
+ rr, err := RepoRootForImportPath(p.ImportPath, IgnoreMod, security)
if err != nil {
return err
}
- vcs, repo, rootPath = rr.vcs, rr.repo, rr.root
+ vcs, repo, rootPath = rr.vcs, rr.Repo, rr.Root
}
- if !blindRepo && !vcs.isSecure(repo) && !*getInsecure {
+ if !blindRepo && !vcs.isSecure(repo) && !Insecure {
return fmt.Errorf("cannot download, %v uses insecure protocol", repo)
}