Skip to content

Commit 917af5d

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 5c4392c + 92309ff commit 917af5d

28 files changed

+244
-95
lines changed

doc/next/6-stdlib/99-minor/net/56025.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[LookupMX] and [(*Resolver).LookupMX] now return DNS names that look
1+
[LookupMX] and [*Resolver.LookupMX] now return DNS names that look
22
like valid IP address, as well as valid domain names.
33
Previously if a name server returned an IP address as a DNS name,
44
LookupMX would discard it, as required by the RFCs.

doc/next/7-ports.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Ports {#ports}
22

3+
### Darwin
4+
5+
<!-- go.dev/issue/69839 -->
6+
As [announced](/doc/go1.24#darwin) in the Go 1.24 release notes, Go 1.25 requires macOS 12 Monterey or later; support for previous versions has been discontinued.
7+
38
### Windows
49

510
<!-- go.dev/issue/71671 -->

src/cmd/go/alldocs.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/auth/auth.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,18 @@ func runGoAuth(client *http.Client, res *http.Response, url string) {
142142
// them to the request headers.
143143
func loadCredential(req *http.Request, url string) bool {
144144
currentPrefix := strings.TrimPrefix(url, "https://")
145+
currentPrefix = strings.TrimSuffix(currentPrefix, "/")
146+
145147
// Iteratively try prefixes, moving up the path hierarchy.
148+
// E.g. example.com/foo/bar, example.com/foo, example.com
146149
for {
147150
headers, ok := credentialCache.Load(currentPrefix)
148151
if !ok {
149-
currentPrefix, _, ok = strings.Cut(currentPrefix, "/")
150-
if !ok {
152+
lastSlash := strings.LastIndexByte(currentPrefix, '/')
153+
if lastSlash == -1 {
151154
return false
152155
}
156+
currentPrefix = currentPrefix[:lastSlash]
153157
continue
154158
}
155159
for key, values := range headers.(http.Header) {
@@ -166,6 +170,7 @@ func loadCredential(req *http.Request, url string) bool {
166170
func storeCredential(prefix string, header http.Header) {
167171
// Trim "https://" prefix to match the format used in .netrc files.
168172
prefix = strings.TrimPrefix(prefix, "https://")
173+
prefix = strings.TrimSuffix(prefix, "/")
169174
if len(header) == 0 {
170175
credentialCache.Delete(prefix)
171176
} else {

src/cmd/go/internal/auth/auth_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,20 @@ func TestCredentialCacheDelete(t *testing.T) {
7171
t.Errorf("loadCredential:\nhave %q\nwant %q", got.Header, want.Header)
7272
}
7373
}
74+
75+
func TestCredentialCacheTrailingSlash(t *testing.T) {
76+
// Store a credential for api.github.com/foo/bar
77+
want := http.Request{Header: make(http.Header)}
78+
want.SetBasicAuth("user", "pwd")
79+
storeCredential("api.github.com/foo", want.Header)
80+
got := &http.Request{Header: make(http.Header)}
81+
ok := loadCredential(got, "api.github.com/foo/bar")
82+
if !ok || !reflect.DeepEqual(got.Header, want.Header) {
83+
t.Errorf("parseNetrc:\nhave %q\nwant %q", got.Header, want.Header)
84+
}
85+
got2 := &http.Request{Header: make(http.Header)}
86+
ok = loadCredential(got2, "https://api.github.com/foo/bar/")
87+
if !ok || !reflect.DeepEqual(got2.Header, want.Header) {
88+
t.Errorf("parseNetrc:\nhave %q\nwant %q", got2.Header, want.Header)
89+
}
90+
}

src/cmd/go/internal/help/helpdoc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ command
10271027
BlankLine = '\n' .
10281028
10291029
Example:
1030-
https://example.com/
1030+
https://example.com
10311031
https://example.net/api/
10321032
10331033
Authorization: Basic <token>

src/cmd/go/internal/load/pkg.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,15 +2577,29 @@ func (p *Package) setBuildInfo(ctx context.Context, autoVCS bool) {
25772577
}
25782578
appendSetting("vcs.modified", strconv.FormatBool(st.Uncommitted))
25792579
// Determine the correct version of this module at the current revision and update the build metadata accordingly.
2580-
repo := modfetch.LookupLocal(ctx, repoDir)
2580+
rootModPath := goModPath(repoDir)
2581+
// If no root module is found, skip embedding VCS data since we cannot determine the module path of the root.
2582+
if rootModPath == "" {
2583+
goto omitVCS
2584+
}
2585+
codeRoot, _, ok := module.SplitPathVersion(rootModPath)
2586+
if !ok {
2587+
goto omitVCS
2588+
}
2589+
repo := modfetch.LookupLocal(ctx, codeRoot, p.Module.Path, repoDir)
25812590
revInfo, err := repo.Stat(ctx, st.Revision)
25822591
if err != nil {
25832592
goto omitVCS
25842593
}
25852594
vers := revInfo.Version
25862595
if vers != "" {
25872596
if st.Uncommitted {
2588-
vers += "+dirty"
2597+
// SemVer build metadata is dot-separated https://semver.org/#spec-item-10
2598+
if strings.HasSuffix(vers, "+incompatible") {
2599+
vers += ".dirty"
2600+
} else {
2601+
vers += "+dirty"
2602+
}
25892603
}
25902604
info.Main.Version = vers
25912605
}

src/cmd/go/internal/modfetch/repo.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,23 +222,27 @@ func Lookup(ctx context.Context, proxy, path string) Repo {
222222

223223
var lookupLocalCache par.Cache[string, Repo] // path, Repo
224224

225-
// LookupLocal will only use local VCS information to fetch the Repo.
226-
func LookupLocal(ctx context.Context, path string) Repo {
225+
// LookupLocal returns a Repo that accesses local VCS information.
226+
//
227+
// codeRoot is the module path of the root module in the repository.
228+
// path is the module path of the module being looked up.
229+
// dir is the file system path of the repository containing the module.
230+
func LookupLocal(ctx context.Context, codeRoot string, path string, dir string) Repo {
227231
if traceRepo {
228232
defer logCall("LookupLocal(%q)", path)()
229233
}
230234

231235
return lookupLocalCache.Do(path, func() Repo {
232236
return newCachingRepo(ctx, path, func(ctx context.Context) (Repo, error) {
233-
repoDir, vcsCmd, err := vcs.FromDir(path, "", true)
237+
repoDir, vcsCmd, err := vcs.FromDir(dir, "", true)
234238
if err != nil {
235239
return nil, err
236240
}
237241
code, err := lookupCodeRepo(ctx, &vcs.RepoRoot{Repo: repoDir, Root: repoDir, VCS: vcsCmd}, true)
238242
if err != nil {
239243
return nil, err
240244
}
241-
r, err := newCodeRepo(code, repoDir, path)
245+
r, err := newCodeRepo(code, codeRoot, path)
242246
if err == nil && traceRepo {
243247
r = newLoggingRepo(r)
244248
}

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

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ exec git branch -m main
3434
# Use a 0.0.0 pseudo-version when no tags are present.
3535
go build
3636
go version -m example$GOEXE
37-
stdout '\s+mod\s+example\s+v0.0.0-20220719150700-b52f952448d2\s+'
37+
stdout '\s+mod\s+example\s+v0.0.0-20220719150700-e7537ba8fd6d\s+'
3838
rm example$GOEXE
3939

4040
# Use a 0.0.0 pseudo-version if the current tag is not a valid semantic version.
4141
exec git tag 1.0.1
4242
go build
4343
go version -m example$GOEXE
44-
stdout '\s+mod\s+example\s+v0.0.0-20220719150700-b52f952448d2\s+'
44+
stdout '\s+mod\s+example\s+v0.0.0-20220719150700-e7537ba8fd6d\s+'
4545
rm example$GOEXE
4646

4747
# Use the current tag which has a valid semantic version to stamp the version.
@@ -79,14 +79,14 @@ exec git commit -m 'commit 3'
7979
# Use a pseudo-version when current commit doesn't match a tagged version.
8080
go build
8181
go version -m example$GOEXE
82-
stdout '\s+mod\s+example\s+v1.0.3-0.20220719150702-deaeab06f7fe\s+'
82+
stdout '\s+mod\s+example\s+v1.0.3-0.20220719150702-b0226f18a7ae\s+'
8383
rm example$GOEXE
8484

8585
# Use pseudo+dirty when uncommitted changes are present.
8686
mv README2 README3
8787
go build
8888
go version -m example$GOEXE
89-
stdout '\s+mod\s+example\s+v1.0.3-0.20220719150702-deaeab06f7fe\+dirty\s+'
89+
stdout '\s+mod\s+example\s+v1.0.3-0.20220719150702-b0226f18a7ae\+dirty\s+'
9090
rm example$GOEXE
9191

9292
# Make sure we always use the previously tagged version to generate the pseudo-version at a untagged revision.
@@ -105,9 +105,83 @@ exec git tag v1.0.4
105105
exec git checkout ':/commit 4'
106106
go build
107107
go version -m example$GOEXE
108-
stdout '\s+mod\s+example\s+v1.0.3-0.20220719150703-2e239bf29c13\s+'
108+
stdout '\s+mod\s+example\s+v1.0.3-0.20220719150703-2ebc76937b49\s+'
109109
rm example$GOEXE
110110

111+
# Create +incompatible module
112+
exec git checkout v1.0.4
113+
exec git rm go.mod
114+
exec git commit -m 'commit 6'
115+
exec git tag v2.0.0
116+
exec git checkout HEAD^ go.mod
117+
# And make the tree +dirty
118+
mv README4 README5
119+
go build
120+
go version -m example$GOEXE
121+
stdout '\s+mod\s+example\s+v2.0.0\+incompatible.dirty\s+'
122+
rm example$GOEXE
123+
124+
# Make sure v2 works as expected.
125+
exec git checkout v1.0.4
126+
go mod edit -module example/v2
127+
exec git add .
128+
exec git commit -m 'commit 7'
129+
exec git tag v2.1.1
130+
go build
131+
go version -m example$GOEXE
132+
stdout '\s+mod\s+example/v2\s+v2.1.1\s+'
133+
rm example$GOEXE
134+
135+
# v2+dirty
136+
mv README5 README6
137+
go build
138+
go version -m example$GOEXE
139+
stdout '\s+mod\s+example/v2\s+v2.1.1\+dirty\s+'
140+
rm example$GOEXE
141+
142+
# v2+pseudo
143+
exec git add .
144+
exec git commit -m 'commit 8'
145+
go build
146+
go version -m example$GOEXE
147+
stdout '\s+mod\s+example/v2\s+v2.1.2-0.20220719150704-0ebeb94ecde2\s+'
148+
rm example$GOEXE
149+
150+
# v2+pseudo+dirty
151+
mv README6 README7
152+
go build
153+
go version -m example$GOEXE
154+
stdout '\s+mod\s+example/v2\s+v2.1.2-0.20220719150704-0ebeb94ecde2\+dirty\s+'
155+
rm example$GOEXE
156+
157+
# modules in subdirectories should be stamped with the correct tag
158+
exec git add .
159+
cd subdir
160+
exec git commit -m 'commit 9'
161+
go build
162+
go version -m subdir$GOEXE
163+
# missing tag creates a pseudo version with v2.0.0
164+
stdout '\s+mod\s+example/subdir/v2\s+v2.0.0-20220719150704-fbef6799938f\s+'
165+
rm subdir$GOEXE
166+
# tag with subdir
167+
exec git tag subdir/v2.1.0
168+
go build
169+
go version -m subdir$GOEXE
170+
stdout '\s+mod\s+example/subdir/v2\s+v2.1.0\s+'
171+
# v2+dirty
172+
mv ../README7 README8
173+
go build
174+
go version -m subdir$GOEXE
175+
stdout '\s+mod\s+example/subdir/v2\s+v2.1.0\+dirty\s+'
176+
rm subdir$GOEXE
177+
178+
# modules in a subdirectory without a go.mod in the root should result in (devel)
179+
rm ../go.mod
180+
go build
181+
go version -m subdir$GOEXE
182+
stdout '\s+mod\s+example/subdir/v2\s+\(devel\)\s+'
183+
rm subdir$GOEXE
184+
111185
-- $WORK/repo/go.mod --
112186
module example
113187

@@ -120,6 +194,17 @@ func main() {
120194
-- $WORK/copy/README --
121195
hello
122196

197+
-- $WORK/repo/subdir/go.mod --
198+
module example/subdir/v2
199+
200+
go 1.18
201+
202+
-- $WORK/repo/subdir/main.go --
203+
package main
204+
205+
func main() {
206+
}
207+
123208
-- $WORK/home/gopher/.gitconfig --
124209
[user]
125210
name = Go Gopher

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ stdout '^\tbuild\tvcs.modified=true$'
4444
cd ..
4545

4646
# Revision and commit time are tagged for repositories with commits.
47-
exec bzr add a README
47+
exec bzr add a README go.mod
4848
exec bzr commit -m 'initial commit'
4949
cd a
5050
go install
@@ -61,7 +61,7 @@ cd ..
6161
cp README README2
6262
exec bzr add a README2
6363
exec bzr commit -m 'second commit'
64-
exec bzr tag v1.2.3
64+
exec bzr tag a/v1.2.3
6565
cd a
6666
go install
6767
go version -m $GOBIN/a$GOEXE
@@ -114,6 +114,10 @@ exit 1
114114
-- repo/README --
115115
Far out in the uncharted backwaters of the unfashionable end of the western
116116
spiral arm of the Galaxy lies a small, unregarded yellow sun.
117+
-- repo/go.mod --
118+
module example.com
119+
120+
go 1.18
117121
-- repo/a/go.mod --
118122
module example.com/a
119123

0 commit comments

Comments
 (0)