diff options
| author | Eric Lagergren <eric@ericlagergren.com> | 2019-08-28 16:29:14 -0700 |
|---|---|---|
| committer | Josh Bleecher Snyder <josharian@gmail.com> | 2019-11-09 00:12:09 +0000 |
| commit | 44454f6a837226d68c264174b72b85084f01c1a7 (patch) | |
| tree | d3bd91a94feebb0092729a046d43e71f661380b9 | |
| parent | 85688492bf1b598c999c025b9d626ae298968a43 (diff) | |
| download | go-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>
| -rw-r--r-- | git-codereview/branch.go | 1 | ||||
| -rw-r--r-- | git-codereview/review.go | 11 | ||||
| -rw-r--r-- | git-codereview/util_test.go | 1 |
3 files changed, 13 insertions, 0 deletions
diff --git a/git-codereview/branch.go b/git-codereview/branch.go index 0a277ce..a332256 100644 --- a/git-codereview/branch.go +++ b/git-codereview/branch.go @@ -78,6 +78,7 @@ func (b *Branch) OriginBranch() string { envs = append(envs, "MSYS=noglob "+os.Getenv("MSYS")) cmd.Env = envs } + setEnglishLocale(cmd) out, err := cmd.CombinedOutput() if err == nil && len(out) > 0 { 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 } diff --git a/git-codereview/util_test.go b/git-codereview/util_test.go index 7065da2..3f4dce6 100644 --- a/git-codereview/util_test.go +++ b/git-codereview/util_test.go @@ -236,6 +236,7 @@ func remove(t *testing.T, file string) { func trun(t *testing.T, dir string, cmdline ...string) string { cmd := exec.Command(cmdline[0], cmdline[1:]...) cmd.Dir = dir + setEnglishLocale(cmd) out, err := cmd.CombinedOutput() if err != nil { if cmdline[0] == "git" { |
