Skip to content

Commit d02fceb

Browse files
rleungxgopherbot
authored andcommitted
cmd/go: mod vendor: emit error if any replacement in vendor directory
Fixes #29169 Change-Id: I3a0fd506c45ad999a2fc6f75f9b3e8a5118ad91b Reviewed-on: https://go-review.googlesource.com/c/go/+/156400 Auto-Submit: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Findley <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]>
1 parent f5d21ff commit d02fceb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/cmd/go/internal/modcmd/vendor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ func moduleLine(m, r module.Version) string {
211211
b.WriteString(m.Version)
212212
}
213213
if r.Path != "" {
214+
if strings.HasPrefix(r.Path, "./vendor") || strings.HasPrefix(r.Path, ".\vendor") {
215+
base.Fatalf("go: replacement path %s inside vendor directory", r.Path)
216+
}
214217
b.WriteString(" => ")
215218
b.WriteString(r.Path)
216219
if r.Version != "" {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
env GO111MODULE=on
22

3+
# Replacement should not use a vendor directory as the target.
4+
! go mod vendor
5+
stderr 'replacement path ./vendor/not-rsc.io/quote/v3 inside vendor directory'
6+
7+
cp go.mod1 go.mod
8+
rm -r vendor
9+
310
# Before vendoring, we expect to see the original directory.
411
go list -f '{{with .Module}}{{.Version}}{{end}} {{.Dir}}' rsc.io/quote/v3
512
stdout 'v3.0.0'
@@ -34,8 +41,15 @@ stderr 'rsc.io/quote/[email protected] used for two different module paths \(not-rsc.io/
3441
-- go.mod --
3542
module example.com/replace
3643

44+
require rsc.io/quote/v3 v3.0.0
45+
replace rsc.io/quote/v3 => ./vendor/not-rsc.io/quote/v3
46+
47+
-- go.mod1 --
48+
module example.com/replace
49+
3750
require rsc.io/quote/v3 v3.0.0
3851
replace rsc.io/quote/v3 => ./local/not-rsc.io/quote/v3
52+
3953
-- imports.go --
4054
package replace
4155

@@ -67,3 +81,9 @@ replace not-rsc.io/quote/v3 => rsc.io/quote/v3 v3.0.0
6781
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
6882
rsc.io/quote/v3 v3.0.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
6983
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
84+
85+
-- vendor/not-rsc.io/quote/v3/go.mod --
86+
module not-rsc.io/quote/v3
87+
88+
-- vendor/not-rsc.io/quote/v3/quote.go --
89+
package quote

0 commit comments

Comments
 (0)