Control: tags -1 patch fixed-upstream

On Mon, 2020-03-09 at 15:36:32 +1300, Michael Hudson-Doyle wrote:
> forwarded 953276 https://github.com/golang/go/issues/34191

On Mon, 2020-03-09 at 13:57:45 +0100, Dr. Tobias Quathamer wrote:
> reassign 953276 src:golang-1.14 1.14-1
> thanks

> golang-1.13 is about to be removed from unstable and will be superseded
> by golang-1.14.

Thanks. This has now been fixed upstream. I've tested the patch proposed
at <https://go-review.googlesource.com/c/go/+/223340/> and it build
golang-1.14 fine.

Attached the upstream patch.

Regards,
Guillem
From 3e9a81ade2fcd1dff643b0c2ee3099763aedb7dc Mon Sep 17 00:00:00 2001
From: Bryan C. Mills <[email protected]>
Date: Fri, 13 Mar 2020 12:51:09 -0400
Subject: [PATCH] cmd/go/internal/modload: suppress the 'go mod init' hint for GOROOT more aggressively

Previously, we suppressed a `to create a module there, run: … go mod
init' warning only if the config file itself (such as .git/config) was
found in GOROOT. However, our release tarballs don't include the
.git/config, so that case was not encountered, and the warning could
occur based on a config file found in some parent directory (outside
of GOROOT entirely).

Instead, skip the directory walk completely if the working directory
is anywhere in GOROOT.

Fixes #34191

Change-Id: I9f774901bfbb53b700407c4882f37d6339d023fe
---

diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index 8b57d80..436797a 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -624,13 +624,14 @@
 		panic("dir not set")
 	}
 	dir = filepath.Clean(dir)
+	if rel := search.InDir(dir, cfg.BuildContext.GOROOT); rel == "." {
+		// Don't suggest creating a module from $GOROOT/.git/config
+		// or a config file found in any parent of $GOROOT (see #34191).
+		return "", ""
+	}
 	for {
 		for _, name := range altConfigs {
 			if fi, err := os.Stat(filepath.Join(dir, name)); err == nil && !fi.IsDir() {
-				if rel := search.InDir(dir, cfg.BuildContext.GOROOT); rel == "." {
-					// Don't suggest creating a module from $GOROOT/.git/config.
-					return "", ""
-				}
 				return dir, name
 			}
 		}
diff --git a/src/cmd/go/testdata/script/mod_convert_git.txt b/src/cmd/go/testdata/script/mod_convert_git.txt
index ece505a..a1dab6d 100644
--- a/src/cmd/go/testdata/script/mod_convert_git.txt
+++ b/src/cmd/go/testdata/script/mod_convert_git.txt
@@ -18,6 +18,18 @@
 ! go list .
 ! stderr 'go mod init'
 
+# We should also not suggest creating a go.mod file in $GOROOT if its own
+# .git/config has been stripped away and we find one in a parent directory.
+# (https://golang.org/issue/34191)
+env GOROOT=$WORK/parent/goroot
+mkdir $GOROOT
+cd $GOROOT
+! go list .
+! stderr 'go mod init'
+
 -- $WORK/test/.git/config --
 -- $WORK/test/x/x.go --
 package x // import "m/x"
+-- $WORK/parent/.git/config --
+-- $WORK/parent/goroot/README --
+This directory isn't really a GOROOT, but let's pretend that it is.

Reply via email to