1
0
mirror of https://github.com/golang/go synced 2024-11-25 11:07:59 -07:00

goinstall: only suggest -fix for bad imports when appropriate

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5495073
This commit is contained in:
Andrew Gerrand 2011-12-17 13:14:59 +11:00
parent 96a5780db8
commit 76a0783321
2 changed files with 13 additions and 5 deletions

View 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_.\-/]+)?$`) 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. // download checks out or updates the specified package from the remote server.
func download(importPath, srcDir string) (public bool, err error) { func download(importPath, srcDir string) (public bool, err error) {
if strings.Contains(importPath, "..") { if strings.Contains(importPath, "..") {
@ -376,11 +384,7 @@ func download(importPath, srcDir string) (public bool, err error) {
if m := oldGoogleRepo.FindStringSubmatch(importPath); m != nil { if m := oldGoogleRepo.FindStringSubmatch(importPath); m != nil {
fixedPath := "code.google.com/p/" + m[1] + m[3] fixedPath := "code.google.com/p/" + m[1] + m[3]
err = fmt.Errorf( err = &errOldGoogleRepo{fixedPath}
"unsupported import path; should be %q\n"+
"Run goinstall with -fix to gofix the code.",
fixedPath,
)
return return
} }

View File

@ -249,6 +249,10 @@ func install(pkg, parent string) error {
printf("%s: download\n", pkg) printf("%s: download\n", pkg)
public, err = download(pkg, tree.SrcDir()) public, err = download(pkg, tree.SrcDir())
if err != nil { 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} return &DownloadError{pkg, tree.Goroot, err}
} }
} else { } else {