Skip to content

Commit 870e12d

Browse files
cuonglmBryan C. Mills
authored and
Bryan C. Mills
committed
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 <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 5a720d2 commit 870e12d

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/cmd/go/internal/get/vcs.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package get
66

77
import (
8-
"bytes"
98
"encoding/json"
109
"errors"
1110
"fmt"
@@ -428,19 +427,18 @@ func (v *vcsCmd) run1(dir string, cmdline string, keyval []string, verbose bool)
428427
fmt.Printf("cd %s\n", dir)
429428
fmt.Printf("%s %s\n", v.cmd, strings.Join(args, " "))
430429
}
431-
var buf bytes.Buffer
432-
cmd.Stdout = &buf
433-
cmd.Stderr = &buf
434-
err = cmd.Run()
435-
out := buf.Bytes()
430+
out, err := cmd.Output()
436431
if err != nil {
437432
if verbose || cfg.BuildV {
438433
fmt.Fprintf(os.Stderr, "# cd %s; %s %s\n", dir, v.cmd, strings.Join(args, " "))
439-
os.Stderr.Write(out)
434+
if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
435+
os.Stderr.Write(ee.Stderr)
436+
} else {
437+
fmt.Fprintf(os.Stderr, err.Error())
438+
}
440439
}
441-
return out, err
442440
}
443-
return out, nil
441+
return out, err
444442
}
445443

446444
// ping pings to determine scheme to use.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
env GIT_TRACE=1
2+
3+
[!net] skip
4+
[!exec:git] skip
5+
6+
# go get should be success when GIT_TRACE set
7+
go get golang.org/x/text

0 commit comments

Comments
 (0)