From d7a8d3eb085ec2c52cf80f6f65bc9ca2ce85a929 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 10 Jul 2015 13:05:02 -0400 Subject: [PATCH] cmd/go: fix go get -u with internal Fixes #11307. Fixes #11055. Change-Id: I8d6b04cb509e62e27d6935b91ffe35fdaea4ebcd Reviewed-on: https://go-review.googlesource.com/12028 Reviewed-by: Ian Lance Taylor Reviewed-by: Andrew Gerrand --- src/cmd/go/get.go | 28 +++++++++++++++++----------- src/cmd/go/go_test.go | 15 +++++++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/cmd/go/get.go b/src/cmd/go/get.go index 3d94602ecf3..48b94d72653 100644 --- a/src/cmd/go/get.go +++ b/src/cmd/go/get.go @@ -80,7 +80,7 @@ func runGet(cmd *Command, args []string) { // Phase 1. Download/update. var stk importStack for _, arg := range downloadPaths(args) { - download(arg, &stk, *getT) + download(arg, nil, &stk, *getT) } exitIfErrors() @@ -152,8 +152,15 @@ var downloadRootCache = map[string]bool{} // download runs the download half of the get command // for the package named by the argument. -func download(arg string, stk *importStack, getTestDeps bool) { - p := loadPackage(arg, stk) +func download(arg string, parent *Package, stk *importStack, getTestDeps bool) { + load := func(path string) *Package { + if parent == nil { + return loadPackage(arg, stk) + } + return loadImport(arg, parent.Dir, nil, stk, nil) + } + + p := load(arg) if p.Error != nil && p.Error.hard { errorf("%s", p.Error) return @@ -186,14 +193,15 @@ func download(arg string, stk *importStack, getTestDeps bool) { wildcardOkay := len(*stk) == 0 isWildcard := false + stk.push(arg) + defer stk.pop() + // Download if the package is missing, or update if we're using -u. if p.Dir == "" || *getU { // The actual download. - stk.push(p.ImportPath) err := downloadPackage(p) if err != nil { errorf("%s", &PackageError{ImportStack: stk.copy(), Err: err.Error()}) - stk.pop() return } @@ -222,9 +230,7 @@ func download(arg string, stk *importStack, getTestDeps bool) { pkgs = pkgs[:0] for _, arg := range args { - stk.push(arg) - p := loadPackage(arg, stk) - stk.pop() + p := load(arg) if p.Error != nil { errorf("%s", p.Error) continue @@ -256,16 +262,16 @@ func download(arg string, stk *importStack, getTestDeps bool) { // Process dependencies, now that we know what they are. for _, dep := range p.deps { // Don't get test dependencies recursively. - download(dep.ImportPath, stk, false) + download(dep.ImportPath, p, stk, false) } if getTestDeps { // Process test dependencies when -t is specified. // (Don't get test dependencies for test dependencies.) for _, path := range p.TestImports { - download(path, stk, false) + download(path, p, stk, false) } for _, path := range p.XTestImports { - download(path, stk, false) + download(path, p, stk, false) } } diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 12010fff420..3b0b112cb04 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -1506,6 +1506,21 @@ func TestGoGetDashTIssue8181(t *testing.T) { tg.grepStdout("x/build/cmd/cl", "missing expected x/build/cmd/cl") } +func TestIssue11307(t *testing.T) { + // go get -u was not working except in checkout directory + if testing.Short() { + t.Skip("skipping test that uses network in short mode") + } + + tg := testgo(t) + defer tg.cleanup() + tg.parallel() + tg.makeTempdir() + tg.setenv("GOPATH", tg.path(".")) + tg.run("get", "github.com/rsc/go-get-issue-11307") + tg.run("get", "-u", "github.com/rsc/go-get-issue-11307") // was failing +} + func TestShadowingLogic(t *testing.T) { tg := testgo(t) defer tg.cleanup()