git-codereview: isolate tests from user's global git config

The test harness creates ephemeral git repositories via gitTest and
runs commands like "git tag work" without a message. When a user has
tag.gpgsign or commit.gpgsign enabled in their global git config, those
settings are inherited by the test repos and cause failures: signed
tags require a message, so "git tag work" aborts with "fatal: no tag
message?".

Rather than disable the specific settings that bite us today, set
GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM to os.DevNull in trun so every
test git invocation runs with no global or system config at all. This
forecloses the entire class of "user config leaks into tests" bugs
(gpg signing, init.defaultBranch, core.autocrlf, custom hooks, signing
keys, aliases, ...) instead of stamping out one symptom.

Tradeoffs worth noting for the interested reader:

  - GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM were added in git 2.32
    (June 2021), so this raises the minimum git version required to
    run the test suite. The tool itself is unaffected.

  - trun is also used for non-git commands; setting these env vars
    unconditionally is harmless because non-git binaries ignore them,
    and keeping the call site unconditional keeps trun simple.

  - os.DevNull (rather than a hard-coded "/dev/null") is used so the
    isolation works on Windows, where the equivalent path is "NUL".

Change-Id: Iafdef28241c81e30cb4f7898da0e5eeb4b7f0872
Reviewed-on: https://go-review.googlesource.com/c/review/+/772280
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
diff --git a/git-codereview/util_test.go b/git-codereview/util_test.go
index 931d017..355bc84 100644
--- a/git-codereview/util_test.go
+++ b/git-codereview/util_test.go
@@ -271,6 +271,10 @@
 	cmd := exec.Command(cmdline[0], cmdline[1:]...)
 	cmd.Dir = dir
 	setEnglishLocale(cmd)
+	// Isolate test git invocations from the user's global and system git
+	// config so settings like commit.gpgsign or init.defaultBranch can't
+	// leak in and break tests. Requires git 2.32+ (June 2021).
+	cmd.Env = append(cmd.Env, "GIT_CONFIG_GLOBAL="+os.DevNull, "GIT_CONFIG_SYSTEM="+os.DevNull)
 	out, err := cmd.CombinedOutput()
 	if err != nil {
 		t.Helper()