diff options
| author | Olivier Mengué <olivier.mengue@gmail.com> | 2026-04-02 13:06:28 +0200 |
|---|---|---|
| committer | Michael Matloob <matloob@google.com> | 2026-04-09 07:51:17 -0700 |
| commit | 15da1c91cd35ccf8129464ee10997622eac7cdc5 (patch) | |
| tree | 74f0c1ca7e7203aad0bd97ba6485c32d85c95b50 | |
| parent | e122bcdc9d567c21a72ba5851488edbd073d7bfe (diff) | |
| download | go-15da1c91cd35ccf8129464ee10997622eac7cdc5.tar.xz | |
cmd/go/internal/modload: fix logged filename for 'go mod init -modfile'
Fix 'go mod init -modfile=tools.mod module' which prints
'creating new go.mod' instead of 'creating new tools.mod'.
Note that -modfile already works, but isn't yet documented
and this is the subject of proposal #78503, so this patch is the minimal
patch to make the feature work better with the existing testsuite,
but more test cases will have to be added once the proposal is approved.
Change-Id: Ia4a7c9b6fb71b4365cbe5f3b70a7af6011b9e089
Reviewed-on: https://go-review.googlesource.com/c/go/+/761781
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
| -rw-r--r-- | src/cmd/go/internal/modload/init.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go index f44b67b510..d8405ae4b6 100644 --- a/src/cmd/go/internal/modload/init.go +++ b/src/cmd/go/internal/modload/init.go @@ -1203,7 +1203,11 @@ func CreateModFile(ld *Loader, ctx context.Context, modPath string) { } checkModulePath(modPath) - fmt.Fprintf(os.Stderr, "go: creating new go.mod: module %s\n", modPath) + if cfg.ModFile != "" { + fmt.Fprintf(os.Stderr, "go: creating new go.mod (using -modfile path %s): module %s\n", base.ShortPath(modFilePath), modPath) + } else { + fmt.Fprintf(os.Stderr, "go: creating new go.mod: module %s\n", modPath) + } modFile := new(modfile.File) modFile.AddModuleStmt(modPath) ld.MainModules = makeMainModules(ld, []module.Version{modFile.Module.Mod}, []string{modRoot}, []*modfile.File{modFile}, []*modFileIndex{nil}, nil) |
