mirror of
https://github.com/golang/go
synced 2024-11-23 19:50:06 -07: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:
parent
5a720d229d
commit
870e12d7bf
@ -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.
|
||||
|
7
src/cmd/go/testdata/script/get_with_git_trace.txt
vendored
Normal file
7
src/cmd/go/testdata/script/get_with_git_trace.txt
vendored
Normal 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
|
Loading…
Reference in New Issue
Block a user