Skip to content

Commit b99fdb2

Browse files
committed
cmd/go: report correct directory for 'no version control'
The scan starts at the directory we care about and works backward to the GOPATH root. The error should say the original directory name, not the name of the GOPATH root. Fixes #6175. R=golang-dev, minux.ma CC=golang-dev https://golang.org/cl/13366050
1 parent 6034406 commit b99fdb2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/cmd/go/test.bash

+12
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ if ! ./testgo test ./testdata/testimport/*.go; then
139139
ok=false
140140
fi
141141

142+
TEST version control error message includes correct directory
143+
export GOPATH=$(pwd)/testdata/shadow/root1
144+
if ./testgo get -u foo 2>testdata/err; then
145+
echo "go get -u foo succeeded unexpectedly"
146+
ok=false
147+
elif ! grep testdata/shadow/root1/src/foo testdata/err >/dev/null; then
148+
echo "go get -u error does not mention shadow/root1/src/foo:"
149+
cat testdata/err
150+
ok=false
151+
fi
152+
unset GOPATH
153+
142154
# Test that without $GOBIN set, binaries get installed
143155
# into the GOPATH bin directory.
144156
TEST install into GOPATH

src/cmd/go/vcs.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ func vcsForDir(p *Package) (vcs *vcsCmd, root string, err error) {
321321
return nil, "", fmt.Errorf("directory %q is outside source root %q", dir, srcRoot)
322322
}
323323

324+
origDir := dir
324325
for len(dir) > len(srcRoot) {
325326
for _, vcs := range vcsList {
326327
if fi, err := os.Stat(filepath.Join(dir, "."+vcs.cmd)); err == nil && fi.IsDir() {
@@ -337,7 +338,7 @@ func vcsForDir(p *Package) (vcs *vcsCmd, root string, err error) {
337338
dir = ndir
338339
}
339340

340-
return nil, "", fmt.Errorf("directory %q is not using a known version control system", dir)
341+
return nil, "", fmt.Errorf("directory %q is not using a known version control system", origDir)
341342
}
342343

343344
// repoRoot represents a version control system, a repo, and a root of

0 commit comments

Comments
 (0)