internal/stdlib: ignore global/system git config Otherwise options such as commit.gpgSign could cause test failures. Change-Id: I35a91ae1156bdf888f93473c514bef00cc6f5dcc Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/783501 kokoro-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Neal Patel <nealpatel@google.com> Reviewed-by: Neal Patel <neal@golang.org> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Hyang-Ah Hana Kim <hyangah@gmail.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/internal/stdlib/gorepo.go b/internal/stdlib/gorepo.go index 142ffc9..7a03d31 100644 --- a/internal/stdlib/gorepo.go +++ b/internal/stdlib/gorepo.go
@@ -132,13 +132,19 @@ type testGoRepo struct { } +func testGitCommand(ctx context.Context, dir string, args ...string) *exec.Cmd { + cmd := exec.CommandContext(ctx, "git", args...) + cmd.Dir = dir + cmd.Env = append(cmd.Environ(), "GIT_CONFIG_GLOBAL="+os.DevNull, "GIT_CONFIG_NOSYSTEM=1") + return cmd +} + func (t *testGoRepo) clone(ctx context.Context, v, directory string) (hash string, err error) { defer derrors.Wrap(&err, "testGoRepo.clone(%q)", v) if v == TestMasterVersion { v = version.Master } - cmd := exec.CommandContext(ctx, "git", "init") - cmd.Dir = directory + cmd := testGitCommand(ctx, directory, "init") if err := cmd.Run(); err != nil { return "", err } @@ -161,8 +167,7 @@ return fmt.Errorf("reading %q: %v", path, err) } os.WriteFile(dstpath, b, 0666) - cmd := exec.CommandContext(ctx, "git", "add", "--", dstpath) - cmd.Dir = directory + cmd := testGitCommand(ctx, directory, "add", "--", dstpath) if err := cmd.Run(); err != nil { return fmt.Errorf("running git add: %v", err) } @@ -171,9 +176,8 @@ if err != nil { return "", err } - cmd = exec.CommandContext(ctx, "git", "commit", "--allow-empty-message", "--author=Joe Random <joe@example.com>", + cmd = testGitCommand(ctx, directory, "commit", "--allow-empty-message", "--author=Joe Random <joe@example.com>", "--message=") - cmd.Dir = directory commitTime := fmt.Sprintf("%v +0000", TestCommitTime.Unix()) name := "Joe Random" email := "joe@example.com" @@ -187,8 +191,7 @@ } return "", fmt.Errorf("running git commit: %v", err) } - cmd = exec.CommandContext(ctx, "git", "rev-parse", "HEAD") - cmd.Dir = directory + cmd = testGitCommand(ctx, directory, "rev-parse", "HEAD") b, err := cmd.Output() if err != nil { if ee, ok := err.(*exec.ExitError); ok {