]> Cypherpunks repositories - gostls13.git/commitdiff
goinstall: only suggest -fix for bad imports when appropriate
authorAndrew Gerrand <adg@golang.org>
Sat, 17 Dec 2011 02:14:59 +0000 (13:14 +1100)
committerAndrew Gerrand <adg@golang.org>
Sat, 17 Dec 2011 02:14:59 +0000 (13:14 +1100)
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5495073

src/cmd/goinstall/download.go
src/cmd/goinstall/main.go

index 11f6f5f4acb2f98df86ec40f328f9ad954657a80..ccce680ce8e553620fc9865c9174b0f9b526c070 100644 (file)
@@ -367,6 +367,14 @@ func (v *vcs) findURL(root string) (string, error) {
 
 var oldGoogleRepo = regexp.MustCompile(`^([a-z0-9\-]+)\.googlecode\.com/(svn|git|hg)(/[a-z0-9A-Z_.\-/]+)?$`)
 
+type errOldGoogleRepo struct {
+       fixedPath string
+}
+
+func (e *errOldGoogleRepo) Error() string {
+       return fmt.Sprintf("unsupported import path; should be %q", e.fixedPath)
+}
+
 // download checks out or updates the specified package from the remote server.
 func download(importPath, srcDir string) (public bool, err error) {
        if strings.Contains(importPath, "..") {
@@ -376,11 +384,7 @@ func download(importPath, srcDir string) (public bool, err error) {
 
        if m := oldGoogleRepo.FindStringSubmatch(importPath); m != nil {
                fixedPath := "code.google.com/p/" + m[1] + m[3]
-               err = fmt.Errorf(
-                       "unsupported import path; should be %q\n"+
-                               "Run goinstall with -fix to gofix the code.",
-                       fixedPath,
-               )
+               err = &errOldGoogleRepo{fixedPath}
                return
        }
 
index 072588457ec0f3aa25cc4b92546bf41da8c7804e..ba8592b54a524c333a3aa1c8c5bc4b40eb9173c4 100644 (file)
@@ -249,6 +249,10 @@ func install(pkg, parent string) error {
                        printf("%s: download\n", pkg)
                        public, err = download(pkg, tree.SrcDir())
                        if err != nil {
+                               // only suggest -fix if the bad import was not on the command line
+                               if e, ok := err.(*errOldGoogleRepo); ok && parent != "" {
+                                       err = fmt.Errorf("%v\nRun goinstall with -fix to gofix the code.", e)
+                               }
                                return &DownloadError{pkg, tree.Goroot, err}
                        }
                } else {