Commit 29ff86b0 authored by c9s's avatar c9s Committed by Russ Cox

cmd/go: handle error when git remote origin doesn't exist

- 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/10475Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 258bf65d
...@@ -300,22 +300,23 @@ func downloadPackage(p *Package) error { ...@@ -300,22 +300,23 @@ func downloadPackage(p *Package) error {
// Double-check where it came from. // Double-check where it came from.
if *getU && vcs.remoteRepo != nil { if *getU && vcs.remoteRepo != nil {
dir := filepath.Join(p.build.SrcRoot, rootPath) dir := filepath.Join(p.build.SrcRoot, rootPath)
if remote, err := vcs.remoteRepo(vcs, dir); err == nil { remote, err := vcs.remoteRepo(vcs, dir)
repo = remote if err != nil {
return err
if !*getF { }
if rr, err := repoRootForImportPath(p.ImportPath, security); err == nil { repo = remote
repo := rr.repo if !*getF {
if rr.vcs.resolveRepo != nil { if rr, err := repoRootForImportPath(p.ImportPath, security); err == nil {
resolved, err := rr.vcs.resolveRepo(rr.vcs, dir, repo) repo := rr.repo
if err == nil { if rr.vcs.resolveRepo != nil {
repo = resolved 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)
} }
} }
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)
}
} }
} }
} }
......
...@@ -147,8 +147,14 @@ var vcsGit = &vcsCmd{ ...@@ -147,8 +147,14 @@ var vcsGit = &vcsCmd{
func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error) { func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error) {
cmd := "config remote.origin.url" cmd := "config remote.origin.url"
errParse := errors.New("unable to parse output of git " + cmd) 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 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 return "", err
} }
repoURL, err := url.Parse(strings.TrimSpace(string(outb))) repoURL, err := url.Parse(strings.TrimSpace(string(outb)))
...@@ -333,7 +339,7 @@ func (v *vcsCmd) run1(dir string, cmdline string, keyval []string, verbose bool) ...@@ -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, " ")) fmt.Fprintf(os.Stderr, "# cd %s; %s %s\n", dir, v.cmd, strings.Join(args, " "))
os.Stderr.Write(out) os.Stderr.Write(out)
} }
return nil, err return out, err
} }
return out, nil return out, nil
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment