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>
1 file changed
tree: 56fff4904bd179d7296742c672e60368c79fe7b6
  1. git-codereview/
  2. .gitattributes
  3. codereview.cfg
  4. CONTRIBUTING.md
  5. go.mod
  6. LICENSE
  7. PATENTS
  8. README.md
README.md

git-codereview

The git-codereview tool is a command-line tool for working with Gerrit.

Download/Install

The easiest way to install is to run go install golang.org/x/review/git-codereview@latest.

Run git codereview hooks to install Gerrit hooks for your git repository.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://go.dev/doc/contribute.

The git repository is https://go.googlesource.com/review.

The main issue tracker for the review repository is located at https://go.dev/issues. Prefix your issue with “x/review:” in the subject line, so it is easy to find.