1
0
mirror of https://github.com/golang/go synced 2024-07-08 12:18:55 +00:00

cmd/go: fix go get fail when GIT_TRACE set

GIT_TRACE write message to stderr, while run1 merge both stdout and
stderr. So function which call run1 and rely on its output will failed
to parse the result when run1 success.

By using cmd.Output(), we ensure only cmd standard out is returned.

Fixes #19682

Change-Id: I7002df17fe68aea1860ddc7382c68cc23548bd90
Reviewed-on: https://go-review.googlesource.com/126735
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
LE Manh Cuong 2018-07-31 01:11:32 +07:00 committed by Bryan C. Mills
parent 5a720d229d
commit 870e12d7bf
2 changed files with 14 additions and 9 deletions

View File

@ -5,7 +5,6 @@
package get
import (
"bytes"
"encoding/json"
"errors"
"fmt"
@ -428,19 +427,18 @@ func (v *vcsCmd) run1(dir string, cmdline string, keyval []string, verbose bool)
fmt.Printf("cd %s\n", dir)
fmt.Printf("%s %s\n", v.cmd, strings.Join(args, " "))
}
var buf bytes.Buffer
cmd.Stdout = &buf
cmd.Stderr = &buf
err = cmd.Run()
out := buf.Bytes()
out, err := cmd.Output()
if err != nil {
if verbose || cfg.BuildV {
fmt.Fprintf(os.Stderr, "# cd %s; %s %s\n", dir, v.cmd, strings.Join(args, " "))
os.Stderr.Write(out)
if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
os.Stderr.Write(ee.Stderr)
} else {
fmt.Fprintf(os.Stderr, err.Error())
}
}
return out, err
}
return out, nil
return out, err
}
// ping pings to determine scheme to use.

View File

@ -0,0 +1,7 @@
env GIT_TRACE=1
[!net] skip
[!exec:git] skip
# go get should be success when GIT_TRACE set
go get golang.org/x/text