aboutsummaryrefslogtreecommitdiff
path: root/git-codereview/review.go
diff options
context:
space:
mode:
authorEric Lagergren <eric@ericlagergren.com>2019-08-28 16:29:14 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2019-11-09 00:12:09 +0000
commit44454f6a837226d68c264174b72b85084f01c1a7 (patch)
treed3bd91a94feebb0092729a046d43e71f661380b9 /git-codereview/review.go
parent85688492bf1b598c999c025b9d626ae298968a43 (diff)
downloadgo-x-review-44454f6a837226d68c264174b72b85084f01c1a7.tar.xz
git-codereview: override existing locale with LC_ALL=C
The git-codereview tool shells out to git, then parses the output. However, because git respects a user's locale settings its output might not be in English, confusing git-codereview. Explicitly set the LC_ALL environment variable to the "C" locale, which is a version of US English that should be on all machines. Fixes golang/go#33895 Change-Id: Id06a81046dba58131fc1de602dd9add687846da1 Reviewed-on: https://go-review.googlesource.com/c/review/+/192237 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'git-codereview/review.go')
-rw-r--r--git-codereview/review.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/git-codereview/review.go b/git-codereview/review.go
index a4ea988..afc61d9 100644
--- a/git-codereview/review.go
+++ b/git-codereview/review.go
@@ -196,6 +196,15 @@ func expectZeroArgs(args []string, command string) {
}
}
+func setEnglishLocale(cmd *exec.Cmd) {
+ // Override the existing locale to prevent non-English locales from
+ // interfering with string parsing. See golang.org/issue/33895.
+ if cmd.Env == nil {
+ cmd.Env = os.Environ()
+ }
+ cmd.Env = append(cmd.Env, "LC_ALL=C")
+}
+
func run(command string, args ...string) {
if err := runErr(command, args...); err != nil {
if *verbose == 0 {
@@ -232,6 +241,7 @@ func runDirErr(dir, command string, args ...string) error {
cmd.Stdin = os.Stdin
cmd.Stdout = stdout()
cmd.Stderr = stderr()
+ setEnglishLocale(cmd)
return cmd.Run()
}
@@ -293,6 +303,7 @@ func cmdOutputDirErr(dir, command string, args ...string) (string, error) {
if dir != "." {
cmd.Dir = dir
}
+ setEnglishLocale(cmd)
b, err := cmd.CombinedOutput()
return string(b), err
}