]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix go get -u with internal
authorRuss Cox <rsc@golang.org>
Fri, 10 Jul 2015 17:05:02 +0000 (13:05 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 13 Jul 2015 19:17:17 +0000 (19:17 +0000)
Fixes #11307.
Fixes #11055.

Change-Id: I8d6b04cb509e62e27d6935b91ffe35fdaea4ebcd
Reviewed-on: https://go-review.googlesource.com/12028
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
src/cmd/go/get.go
src/cmd/go/go_test.go

index 3d94602ecf37eaaba2a494848a12b80b0c73ad9e..48b94d726538c11bd808da74a24b29b0980af3c9 100644 (file)
@@ -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)
                        }
                }
 
index 12010fff420478d1fa514b558ed52e7746c17bb7..3b0b112cb049b71976d1bde4d58fd07be3981fc2 100644 (file)
@@ -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()