]> Cypherpunks repositories - gostls13.git/commit
cmd/go: update default go directive in mod or work init
authorIan Alexander <jitsu@google.com>
Thu, 13 Nov 2025 21:38:20 +0000 (16:38 -0500)
committerIan Alexander <jitsu@google.com>
Sat, 22 Nov 2025 14:13:24 +0000 (06:13 -0800)
commit337f7b1f5d18e8b2469a37174c24baced4c23801
treeebf6d42212fd683a324dd9cfe650d63a806e1f63
parent3c26aef8fba0ef1f4d26d802ba037b43671924e9
cmd/go: update default go directive in mod or work init

This commit updates the default go directive when initializing a new
module.

The current logic is to use the latest version supported by the
toolchain.  This behavior is simple, predictable, and importantly, it
can work while completely offline (i.e., no internet connection
required).

This commit changes the default version to the following behavior:

* If the current toolchain version is a stable version of Go 1.N.M,
default to go 1.(N-1).0
* If the current toolchain version is a pre-release version of Go
1.N (Release Candidate M) or a development version of Go 1.N, default
to go 1.(N-2).0

This behavior maintains the property of being able to work offline.

Fixes #74748.

Change-Id: I81f62eef29f1dd51060067c8075f61e7bcf57c20
Reviewed-on: https://go-review.googlesource.com/c/go/+/720480
Commit-Queue: Ian Alexander <jitsu@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Bypass: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
src/cmd/go/internal/modload/init.go
src/cmd/go/internal/workcmd/init.go
src/cmd/go/testdata/script/mod_edit.txt
src/cmd/go/testdata/script/mod_init_version.txt [new file with mode: 0644]
src/cmd/go/testdata/script/work.txt
src/cmd/go/testdata/script/work_edit.txt
src/cmd/go/testdata/script/work_init_path.txt
src/cmd/go/testdata/script/work_init_toolchain.txt
src/cmd/go/testdata/script/work_init_version.txt [new file with mode: 0644]
src/cmd/go/testdata/script/work_sync_toolchain.txt
src/cmd/go/testdata/script/work_use_toolchain.txt