]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: ignore custom import check when there is no import comment
authorRoss Light <light@google.com>
Thu, 4 Jun 2015 18:45:50 +0000 (11:45 -0700)
committerRuss Cox <rsc@golang.org>
Sat, 27 Jun 2015 19:06:56 +0000 (19:06 +0000)
Fixes #10952

Change-Id: I56ab6a806bd3741cffd9d2a53929a6d043626a26
Reviewed-on: https://go-review.googlesource.com/10693
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/get.go
src/cmd/go/go_test.go

index e76be651ae54b1c45f6a570090f51e4c5044992b..3d94602ecf37eaaba2a494848a12b80b0c73ad9e 100644 (file)
@@ -314,7 +314,7 @@ func downloadPackage(p *Package) error {
                                                        repo = resolved
                                                }
                                        }
-                                       if remote != repo {
+                                       if remote != repo && p.ImportComment != "" {
                                                return fmt.Errorf("%s is a custom import path for %s, but %s is checked out from %s", rr.root, repo, dir, remote)
                                        }
                                }
index e70bff0bbd54d39890dccf2fc71423a64749898e..028ffd8a5967234fa7b14af51817e24230f6bb15 100644 (file)
@@ -278,6 +278,30 @@ func (tg *testgoData) runFail(args ...string) {
        }
 }
 
+// runGit runs a git command, and expects it to succeed.
+func (tg *testgoData) runGit(dir string, args ...string) {
+       cmd := exec.Command("git", args...)
+       tg.stdout.Reset()
+       tg.stderr.Reset()
+       cmd.Stdout = &tg.stdout
+       cmd.Stderr = &tg.stderr
+       cmd.Dir = dir
+       cmd.Env = tg.env
+       status := cmd.Run()
+       if tg.stdout.Len() > 0 {
+               tg.t.Log("git standard output:")
+               tg.t.Log(tg.stdout.String())
+       }
+       if tg.stderr.Len() > 0 {
+               tg.t.Log("git standard error:")
+               tg.t.Log(tg.stderr.String())
+       }
+       if status != nil {
+               tg.t.Logf("git %v failed unexpectedly: %v", args, status)
+               tg.t.FailNow()
+       }
+}
+
 // getStdout returns standard output of the testgo run as a string.
 func (tg *testgoData) getStdout() string {
        if !tg.ran {
@@ -932,6 +956,24 @@ func TestImportCommentConflict(t *testing.T) {
        tg.grepStderr("found import comments", "go build did not mention comment conflict")
 }
 
+// cmd/go: custom import path checking should not apply to github.com/xxx/yyy.
+func TestIssue10952(t *testing.T) {
+       if _, err := exec.LookPath("git"); err != nil {
+               t.Skip("skipping because git binary not found")
+       }
+
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.parallel()
+       tg.tempDir("src")
+       tg.setenv("GOPATH", tg.path("."))
+       const importPath = "github.com/zombiezen/go-get-issue-10952"
+       tg.run("get", "-d", "-u", importPath)
+       repoDir := tg.path("src/" + importPath)
+       tg.runGit(repoDir, "remote", "set-url", "origin", "https://"+importPath+".git")
+       tg.run("get", "-d", "-u", importPath)
+}
+
 func TestDisallowedCSourceFiles(t *testing.T) {
        tg := testgo(t)
        defer tg.cleanup()