]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: handle error when git remote origin doesn't exist
authorc9s <yoanlin93@gmail.com>
Fri, 29 May 2015 17:12:35 +0000 (01:12 +0800)
committerRuss Cox <rsc@golang.org>
Sat, 27 Jun 2015 18:43:15 +0000 (18:43 +0000)
- Let runOutput return the error message
- When `git config ...` returns empty buffer, it means the config key is
  correct, but there is no corresponding value.
- Return the correct error when the url of remote origin is not found.
- Update error message

Fixes: #10922
Change-Id: I3f8880f6717a4f079b840d1249174378d36bca1b
Reviewed-on: https://go-review.googlesource.com/10475
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/get.go
src/cmd/go/vcs.go

index 940b2639a1fd87da71ea774947b4a15e2dbb0003..e76be651ae54b1c45f6a570090f51e4c5044992b 100644 (file)
@@ -300,22 +300,23 @@ func downloadPackage(p *Package) error {
                // Double-check where it came from.
                if *getU && vcs.remoteRepo != nil {
                        dir := filepath.Join(p.build.SrcRoot, rootPath)
-                       if remote, err := vcs.remoteRepo(vcs, dir); err == nil {
-                               repo = remote
-
-                               if !*getF {
-                                       if rr, err := repoRootForImportPath(p.ImportPath, security); err == nil {
-                                               repo := rr.repo
-                                               if rr.vcs.resolveRepo != nil {
-                                                       resolved, err := rr.vcs.resolveRepo(rr.vcs, dir, repo)
-                                                       if err == nil {
-                                                               repo = resolved
-                                                       }
-                                               }
-                                               if remote != repo {
-                                                       return fmt.Errorf("%s is a custom import path for %s, but %s is checked out from %s", rr.root, repo, dir, remote)
+                       remote, err := vcs.remoteRepo(vcs, dir)
+                       if err != nil {
+                               return err
+                       }
+                       repo = remote
+                       if !*getF {
+                               if rr, err := repoRootForImportPath(p.ImportPath, security); err == nil {
+                                       repo := rr.repo
+                                       if rr.vcs.resolveRepo != nil {
+                                               resolved, err := rr.vcs.resolveRepo(rr.vcs, dir, repo)
+                                               if err == nil {
+                                                       repo = resolved
                                                }
                                        }
+                                       if remote != repo {
+                                               return fmt.Errorf("%s is a custom import path for %s, but %s is checked out from %s", rr.root, repo, dir, remote)
+                                       }
                                }
                        }
                }
index b1db0deba74ecc2bf689d901d38eef14c5eecf0e..d8f8873bbdcd51b0b3799637f894b4da993473b5 100644 (file)
@@ -147,8 +147,14 @@ var vcsGit = &vcsCmd{
 func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error) {
        cmd := "config remote.origin.url"
        errParse := errors.New("unable to parse output of git " + cmd)
-       outb, err := vcsGit.runOutput(rootDir, cmd)
+       errRemoteOriginNotFound := errors.New("remote origin not found")
+       outb, err := vcsGit.run1(rootDir, cmd, nil, false)
        if err != nil {
+               // if it doesn't output any message, it means the config argument is correct,
+               // but the config value itself doesn't exist
+               if outb != nil && len(outb) == 0 {
+                       return "", errRemoteOriginNotFound
+               }
                return "", err
        }
        repoURL, err := url.Parse(strings.TrimSpace(string(outb)))
@@ -333,7 +339,7 @@ func (v *vcsCmd) run1(dir string, cmdline string, keyval []string, verbose bool)
                        fmt.Fprintf(os.Stderr, "# cd %s; %s %s\n", dir, v.cmd, strings.Join(args, " "))
                        os.Stderr.Write(out)
                }
-               return nil, err
+               return out, err
        }
        return out, nil
 }