summaryrefslogtreecommitdiff
path: root/src/cmd/go/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/go/main.go')
-rw-r--r--src/cmd/go/main.go37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go
index bf1dad40f..3180dbeed 100644
--- a/src/cmd/go/main.go
+++ b/src/cmd/go/main.go
@@ -108,6 +108,7 @@ func setExitStatus(n int) {
}
func main() {
+ _ = go11tag
flag.Usage = usage
flag.Parse()
log.SetFlags(0)
@@ -129,8 +130,11 @@ func main() {
fmt.Fprintf(os.Stderr, "warning: GOPATH set to GOROOT (%s) has no effect\n", gopath)
} else {
for _, p := range filepath.SplitList(gopath) {
- if strings.Contains(p, "~") && runtime.GOOS != "windows" {
- fmt.Fprintf(os.Stderr, "go: GOPATH entry cannot contain shell metacharacter '~': %q\n", p)
+ // Note: using HasPrefix instead of Contains because a ~ can appear
+ // in the middle of directory elements, such as /tmp/git-1.8.2~rc3
+ // or C:\PROGRA~1. Only ~ as a path prefix has meaning to the shell.
+ if strings.HasPrefix(p, "~") {
+ fmt.Fprintf(os.Stderr, "go: GOPATH entry cannot start with shell metacharacter '~': %q\n", p)
os.Exit(2)
}
if build.IsLocalImport(p) {
@@ -189,6 +193,9 @@ var documentationTemplate = `// Copyright 2011 The Go Authors. All rights reser
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// DO NOT EDIT THIS FILE. GENERATED BY mkdoc.sh.
+// Edit the documentation in other files and rerun mkdoc.sh to generate this one.
+
/*
{{range .}}{{if .Short}}{{.Short | capitalize}}
@@ -386,16 +393,26 @@ func runOut(dir string, cmdargs ...interface{}) []byte {
// child will be faster.
func envForDir(dir string) []string {
env := os.Environ()
- for i, kv := range env {
- if strings.HasPrefix(kv, "PWD=") {
- env[i] = "PWD=" + dir
- return env
- }
- }
// Internally we only use rooted paths, so dir is rooted.
// Even if dir is not rooted, no harm done.
- env = append(env, "PWD="+dir)
- return env
+ return mergeEnvLists([]string{"PWD=" + dir}, env)
+}
+
+// mergeEnvLists merges the two environment lists such that
+// variables with the same name in "in" replace those in "out".
+func mergeEnvLists(in, out []string) []string {
+NextVar:
+ for _, inkv := range in {
+ k := strings.SplitAfterN(inkv, "=", 2)[0]
+ for i, outkv := range out {
+ if strings.HasPrefix(outkv, k) {
+ out[i] = inkv
+ continue NextVar
+ }
+ }
+ out = append(out, inkv)
+ }
+ return out
}
// matchPattern(pattern)(name) reports whether