aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_get_promote_implicit.txt
blob: 9eec2013210350fdd7b4234eeea6160abaa70ec7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
cp go.mod.orig go.mod

# If we list a package in an implicit dependency imported from the main module,
# we should get an error because the dependency should have an explicit
# requirement.
go list -m indirect-with-pkg
stdout '^indirect-with-pkg v1.0.0 => ./indirect-with-pkg$'
! go list ./use-indirect
stderr '^package m/use-indirect imports indirect-with-pkg from implicitly required module; to add missing requirements, run:\n\tgo get indirect-with-pkg@v1.0.0$'

# We can promote the implicit requirement by getting the importing package.
# NOTE: the hint recommends getting the imported package (tested below) since
# it's more obvious and doesn't require -d. However, that adds an '// indirect'
# comment on the requirement.
go get -d m/use-indirect
cmp go.mod go.mod.use
cp go.mod.orig go.mod

# We can also promote implicit requirements using 'go get' on them, or their
# packages. This gives us "// indirect" requirements, since 'go get' doesn't
# know they're needed by the main module. See #43131 for the rationale.
# The hint above recommends this because it's more obvious usage and doesn't
# require the -d flag.
go get -d indirect-with-pkg indirect-without-pkg
cmp go.mod go.mod.indirect

-- go.mod.orig --
module m

go 1.16

require direct v1.0.0

replace (
	direct v1.0.0 => ./direct
	indirect-with-pkg v1.0.0 => ./indirect-with-pkg
	indirect-without-pkg v1.0.0 => ./indirect-without-pkg
)
-- go.mod.use --
module m

go 1.16

require (
	direct v1.0.0
	indirect-with-pkg v1.0.0
)

replace (
	direct v1.0.0 => ./direct
	indirect-with-pkg v1.0.0 => ./indirect-with-pkg
	indirect-without-pkg v1.0.0 => ./indirect-without-pkg
)
-- go.mod.indirect --
module m

go 1.16

require (
	direct v1.0.0
	indirect-with-pkg v1.0.0 // indirect
	indirect-without-pkg v1.0.0 // indirect
)

replace (
	direct v1.0.0 => ./direct
	indirect-with-pkg v1.0.0 => ./indirect-with-pkg
	indirect-without-pkg v1.0.0 => ./indirect-without-pkg
)
-- use-indirect/use-indirect.go --
package use

import _ "indirect-with-pkg"
-- direct/go.mod --
module direct

go 1.16

require (
	indirect-with-pkg v1.0.0
	indirect-without-pkg v1.0.0
)
-- indirect-with-pkg/go.mod --
module indirect-with-pkg

go 1.16
-- indirect-with-pkg/p.go --
package p
-- indirect-without-pkg/go.mod --
module indirect-without-pkg

go 1.16