Skip to content

Commit aa80228

Browse files
author
Bryan C. Mills
committed
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>
1 parent b9d5a25 commit aa80228

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

src/cmd/go/internal/modfetch/coderepo.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ func (r *codeRepo) findDir(version string) (rev, dir string, gomod []byte, err e
792792
file1 := path.Join(r.codeDir, "go.mod")
793793
gomod1, err1 := r.code.ReadFile(rev, file1, codehost.MaxGoMod)
794794
if err1 != nil && !os.IsNotExist(err1) {
795-
return "", "", nil, fmt.Errorf("reading %s/%s at revision %s: %v", r.pathPrefix, file1, rev, err1)
795+
return "", "", nil, fmt.Errorf("reading %s/%s at revision %s: %v", r.codeRoot, file1, rev, err1)
796796
}
797797
mpath1 := modfile.ModulePath(gomod1)
798798
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
810810
file2 = path.Join(dir2, "go.mod")
811811
gomod2, err2 := r.code.ReadFile(rev, file2, codehost.MaxGoMod)
812812
if err2 != nil && !os.IsNotExist(err2) {
813-
return "", "", nil, fmt.Errorf("reading %s/%s at revision %s: %v", r.pathPrefix, file2, rev, err2)
813+
return "", "", nil, fmt.Errorf("reading %s/%s at revision %s: %v", r.codeRoot, file2, rev, err2)
814814
}
815815
mpath2 := modfile.ModulePath(gomod2)
816816
found2 := err2 == nil && isMajor(mpath2, r.pathMajor)
@@ -823,9 +823,9 @@ func (r *codeRepo) findDir(version string) (rev, dir string, gomod []byte, err e
823823
}
824824
if err2 == nil {
825825
if mpath2 == "" {
826-
return "", "", nil, fmt.Errorf("%s/%s is missing module path at revision %s", r.pathPrefix, file2, rev)
826+
return "", "", nil, fmt.Errorf("%s/%s is missing module path at revision %s", r.codeRoot, file2, rev)
827827
}
828-
return "", "", nil, fmt.Errorf("%s/%s has non-...%s module path %q at revision %s", r.pathPrefix, file2, r.pathMajor, mpath2, rev)
828+
return "", "", nil, fmt.Errorf("%s/%s has non-...%s module path %q at revision %s", r.codeRoot, file2, r.pathMajor, mpath2, rev)
829829
}
830830
}
831831

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[short] skip
2+
[!exec:git] skip
3+
[!net] skip
4+
[!linux] skip # Uses XDG_CONFIG_HOME
5+
6+
env GIT_CONFIG_GLOBAL=$WORK/.gitconfig
7+
env GOPROXY=direct
8+
9+
! go mod download
10+
stderr '^go: github\.com/golang/notexist/subdir@v0.1.0: reading github\.com/golang/notexist/subdir/go\.mod at revision subdir/v0\.1\.0: '
11+
12+
-- go.mod --
13+
module test
14+
15+
go 1.18
16+
17+
require github.com/golang/notexist/subdir v0.1.0
18+
19+
-- $WORK/.gitconfig --
20+
[url "git@github.com:"]
21+
insteadOf = https://github.com/

src/cmd/go/testdata/script/mod_download_private_vcs.txt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,18 @@ stderr '^If this is a private repository, see https://golang.org/doc/faq#git_htt
2222
! stderr 'unknown revision'
2323
! stdout .
2424

25-
[!linux] stop # Needs XDG_CONFIG_HOME.
2625
[!exec:false] stop
2726

2827
# Test that Git clone errors will be shown to the user instead of a generic
2928
# "unknown revision" error. To do this we want to force git ls-remote to return
3029
# an error we don't already have special handling for. See golang/go#42751.
31-
#
32-
# Set XDG_CONFIG_HOME to tell Git where to look for the git config file listed
33-
# below, which turns on ssh.
34-
env XDG_CONFIG_HOME=$TMPDIR
30+
env HOME=$WORK${/}home${/}gopher
3531
env GIT_SSH_COMMAND=false
3632
! go install github.com/golang/nonexist@master
3733
stderr 'fatal: Could not read from remote repository.'
3834
! stderr 'unknown revision'
3935
! stdout .
4036

41-
-- $TMPDIR/git/config --
37+
-- $WORK/home/gopher/.gitconfig --
4238
[url "git@github.com:"]
43-
insteadOf = https://github.com/
39+
insteadOf = https://github.com/

0 commit comments

Comments
 (0)