mirror of
https://github.com/golang/go
synced 2024-11-23 10:30:03 -07:00
cmd/go/internal/modfetch: avoid duplicating path components in Git fetch errors
Fixes #51114 Change-Id: Iebfe65f826b7b583ff2b48b8bc9d2eb23f2726af Reviewed-on: https://go-review.googlesource.com/c/go/+/386234 Reviewed-by: Valentin Deleplace <deleplace@google.com> Reviewed-by: Nooras Saba <saba@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
b9d5a25442
commit
aa80228526
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
21
src/cmd/go/testdata/script/mod_download_issue51114.txt
vendored
Normal file
21
src/cmd/go/testdata/script/mod_download_issue51114.txt
vendored
Normal file
@ -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/
|
@ -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/
|
||||
|
Loading…
Reference in New Issue
Block a user