From aa802285265ac370f7ce62299e54ec84635b794e Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 16 Feb 2022 14:07:06 -0500 Subject: [PATCH] cmd/go/internal/modfetch: avoid duplicating path components in Git fetch errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #51114 Change-Id: Iebfe65f826b7b583ff2b48b8bc9d2eb23f2726af Reviewed-on: https://go-review.googlesource.com/c/go/+/386234 Reviewed-by: Valentin Deleplace Reviewed-by: Nooras Saba‎ TryBot-Result: Gopher Robot Run-TryBot: Bryan Mills --- src/cmd/go/internal/modfetch/coderepo.go | 8 +++---- .../script/mod_download_issue51114.txt | 21 +++++++++++++++++++ .../script/mod_download_private_vcs.txt | 10 +++------ 3 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 src/cmd/go/testdata/script/mod_download_issue51114.txt diff --git a/src/cmd/go/internal/modfetch/coderepo.go b/src/cmd/go/internal/modfetch/coderepo.go index b934e362a4a..8fb0035f8c0 100644 --- a/src/cmd/go/internal/modfetch/coderepo.go +++ b/src/cmd/go/internal/modfetch/coderepo.go @@ -792,7 +792,7 @@ func (r *codeRepo) findDir(version string) (rev, dir string, gomod []byte, err e file1 := path.Join(r.codeDir, "go.mod") gomod1, err1 := r.code.ReadFile(rev, file1, codehost.MaxGoMod) if err1 != nil && !os.IsNotExist(err1) { - return "", "", nil, fmt.Errorf("reading %s/%s at revision %s: %v", r.pathPrefix, file1, rev, err1) + return "", "", nil, fmt.Errorf("reading %s/%s at revision %s: %v", r.codeRoot, file1, rev, err1) } mpath1 := modfile.ModulePath(gomod1) found1 := err1 == nil && (isMajor(mpath1, r.pathMajor) || r.canReplaceMismatchedVersionDueToBug(mpath1)) @@ -810,7 +810,7 @@ func (r *codeRepo) findDir(version string) (rev, dir string, gomod []byte, err e file2 = path.Join(dir2, "go.mod") gomod2, err2 := r.code.ReadFile(rev, file2, codehost.MaxGoMod) if err2 != nil && !os.IsNotExist(err2) { - return "", "", nil, fmt.Errorf("reading %s/%s at revision %s: %v", r.pathPrefix, file2, rev, err2) + return "", "", nil, fmt.Errorf("reading %s/%s at revision %s: %v", r.codeRoot, file2, rev, err2) } mpath2 := modfile.ModulePath(gomod2) found2 := err2 == nil && isMajor(mpath2, r.pathMajor) @@ -823,9 +823,9 @@ func (r *codeRepo) findDir(version string) (rev, dir string, gomod []byte, err e } if err2 == nil { if mpath2 == "" { - return "", "", nil, fmt.Errorf("%s/%s is missing module path at revision %s", r.pathPrefix, file2, rev) + return "", "", nil, fmt.Errorf("%s/%s is missing module path at revision %s", r.codeRoot, file2, rev) } - return "", "", nil, fmt.Errorf("%s/%s has non-...%s module path %q at revision %s", r.pathPrefix, file2, r.pathMajor, mpath2, rev) + return "", "", nil, fmt.Errorf("%s/%s has non-...%s module path %q at revision %s", r.codeRoot, file2, r.pathMajor, mpath2, rev) } } diff --git a/src/cmd/go/testdata/script/mod_download_issue51114.txt b/src/cmd/go/testdata/script/mod_download_issue51114.txt new file mode 100644 index 00000000000..92479c6dd3c --- /dev/null +++ b/src/cmd/go/testdata/script/mod_download_issue51114.txt @@ -0,0 +1,21 @@ +[short] skip +[!exec:git] skip +[!net] skip +[!linux] skip # Uses XDG_CONFIG_HOME + +env GIT_CONFIG_GLOBAL=$WORK/.gitconfig +env GOPROXY=direct + +! go mod download +stderr '^go: github\.com/golang/notexist/subdir@v0.1.0: reading github\.com/golang/notexist/subdir/go\.mod at revision subdir/v0\.1\.0: ' + +-- go.mod -- +module test + +go 1.18 + +require github.com/golang/notexist/subdir v0.1.0 + +-- $WORK/.gitconfig -- +[url "git@github.com:"] + insteadOf = https://github.com/ diff --git a/src/cmd/go/testdata/script/mod_download_private_vcs.txt b/src/cmd/go/testdata/script/mod_download_private_vcs.txt index e1267939072..da9fe0290b7 100644 --- a/src/cmd/go/testdata/script/mod_download_private_vcs.txt +++ b/src/cmd/go/testdata/script/mod_download_private_vcs.txt @@ -22,22 +22,18 @@ stderr '^If this is a private repository, see https://golang.org/doc/faq#git_htt ! stderr 'unknown revision' ! stdout . -[!linux] stop # Needs XDG_CONFIG_HOME. [!exec:false] stop # Test that Git clone errors will be shown to the user instead of a generic # "unknown revision" error. To do this we want to force git ls-remote to return # an error we don't already have special handling for. See golang/go#42751. -# -# Set XDG_CONFIG_HOME to tell Git where to look for the git config file listed -# below, which turns on ssh. -env XDG_CONFIG_HOME=$TMPDIR +env HOME=$WORK${/}home${/}gopher env GIT_SSH_COMMAND=false ! go install github.com/golang/nonexist@master stderr 'fatal: Could not read from remote repository.' ! stderr 'unknown revision' ! stdout . --- $TMPDIR/git/config -- +-- $WORK/home/gopher/.gitconfig -- [url "git@github.com:"] - insteadOf = https://github.com/ + insteadOf = https://github.com/