aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_upgrade_patch.txt
blob: b8c178c75e6dd9b79f0a14cbb959d725ee216f9c (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
env GO111MODULE=on
[short] skip

# Initially, we are at v1.0.0 for all dependencies.
go get -d
cp go.mod go.mod.orig
go list -m all
stdout '^patch.example.com/direct v1.0.0'
stdout '^patch.example.com/indirect v1.0.0'
! stdout '^patch.example.com/depofdirectpatch'

# @patch should be rejected for modules not already in the build list.
! go get -d patch.example.com/depofdirectpatch@patch
stderr '^go: can''t query version "patch" of module patch.example.com/depofdirectpatch: no existing version is required$'
cmp go.mod.orig go.mod

# get -u=patch, with no arguments, should patch-update all dependencies
# of the package in the current directory, pulling in transitive dependencies
# and also patching those.
cp go.mod.orig go.mod
go get -d -u=patch
go list -m all
stdout '^patch.example.com/direct v1.0.1'
stdout '^patch.example.com/indirect v1.0.1'
stdout '^patch.example.com/depofdirectpatch v1.0.0'

# 'get all@patch' should patch the modules that provide packages in 'all'.
cp go.mod.orig go.mod
go get -d all@patch
go list -m all
stdout '^patch.example.com/direct v1.0.1'
stdout '^patch.example.com/indirect v1.0.1'
stdout '^patch.example.com/depofdirectpatch v1.0.0'

# ...but 'all@patch' should fail if any of the affected modules do not already
# have a selected version.
cp go.mod.orig go.mod
go mod edit -droprequire=patch.example.com/direct
cp go.mod go.mod.dropped
! go get -d all@patch
stderr '^go: all@patch: can''t query version "patch" of module patch.example.com/direct: no existing version is required$'
cmp go.mod.dropped go.mod

# Requesting the direct dependency with -u=patch but without an explicit version
# should patch-update it and its dependencies.
cp go.mod.orig go.mod
go get -d -u=patch patch.example.com/direct
go list -m all
stdout '^patch.example.com/direct v1.0.1'
stdout '^patch.example.com/indirect v1.0.1'
stdout '^patch.example.com/depofdirectpatch v1.0.0'

# Requesting only the indirect dependency should not update the direct one.
cp go.mod.orig go.mod
go get -d -u=patch patch.example.com/indirect
go list -m all
stdout '^patch.example.com/direct v1.0.0'
stdout '^patch.example.com/indirect v1.0.1'
! stdout '^patch.example.com/depofdirectpatch'

# @patch should apply only to the specific module,
# but the result must reflect its upgraded requirements.
cp go.mod.orig go.mod
go get -d patch.example.com/direct@patch
go list -m all
stdout '^patch.example.com/direct v1.0.1'
stdout '^patch.example.com/indirect v1.0.0'
stdout '^patch.example.com/depofdirectpatch v1.0.0'

# An explicit @patch should override a general -u.
cp go.mod.orig go.mod
go get -d -u patch.example.com/direct@patch
go list -m all
stdout '^patch.example.com/direct v1.0.1'
stdout '^patch.example.com/indirect v1.1.0'
stdout '^patch.example.com/depofdirectpatch v1.0.0'

# An explicit @latest should override a general -u=patch.
cp go.mod.orig go.mod
go get -d -u=patch patch.example.com/direct@latest
go list -m all
stdout '^patch.example.com/direct v1.1.0'
stdout '^patch.example.com/indirect v1.0.1'
! stdout '^patch.example.com/depofdirectpatch'

# Standard library packages cannot be upgraded explicitly.
cp go.mod.orig go.mod
! go get cmd/vet@patch
stderr 'go: can''t request explicit version "patch" of standard library package cmd/vet$'

# However, standard-library packages without explicit versions are fine.
go get -d -u=patch -d cmd/go

# We can upgrade to a new version of a module with no root package.
go get -d example.com/noroot@v1.0.0
go list -m all
stdout '^example.com/noroot v1.0.0$'
go get -d example.com/noroot@patch
go list -m all
stdout '^example.com/noroot v1.0.1$'


-- go.mod --
module x

require patch.example.com/direct v1.0.0

-- main.go --
package x
import _ "patch.example.com/direct"