From 15da1c91cd35ccf8129464ee10997622eac7cdc5 Mon Sep 17 00:00:00 2001 From: Olivier Mengué Date: Thu, 2 Apr 2026 13:06:28 +0200 Subject: 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 Reviewed-by: David Chase Reviewed-by: Michael Matloob Reviewed-by: Michael Matloob --- src/cmd/go/internal/modload/init.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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) -- cgit v1.3