Skip to content

Commit b045357

Browse files
runxiyugopherbot
authored andcommitted
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>
1 parent dd385e7 commit b045357

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

internal/stdlib/gorepo.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,19 @@ func (g *localGoRepo) clone(ctx context.Context, v, directory string) (hash stri
132132
type testGoRepo struct {
133133
}
134134

135+
func testGitCommand(ctx context.Context, dir string, args ...string) *exec.Cmd {
136+
cmd := exec.CommandContext(ctx, "git", args...)
137+
cmd.Dir = dir
138+
cmd.Env = append(cmd.Environ(), "GIT_CONFIG_GLOBAL="+os.DevNull, "GIT_CONFIG_NOSYSTEM=1")
139+
return cmd
140+
}
141+
135142
func (t *testGoRepo) clone(ctx context.Context, v, directory string) (hash string, err error) {
136143
defer derrors.Wrap(&err, "testGoRepo.clone(%q)", v)
137144
if v == TestMasterVersion {
138145
v = version.Master
139146
}
140-
cmd := exec.CommandContext(ctx, "git", "init")
141-
cmd.Dir = directory
147+
cmd := testGitCommand(ctx, directory, "init")
142148
if err := cmd.Run(); err != nil {
143149
return "", err
144150
}
@@ -161,8 +167,7 @@ func (t *testGoRepo) clone(ctx context.Context, v, directory string) (hash strin
161167
return fmt.Errorf("reading %q: %v", path, err)
162168
}
163169
os.WriteFile(dstpath, b, 0666)
164-
cmd := exec.CommandContext(ctx, "git", "add", "--", dstpath)
165-
cmd.Dir = directory
170+
cmd := testGitCommand(ctx, directory, "add", "--", dstpath)
166171
if err := cmd.Run(); err != nil {
167172
return fmt.Errorf("running git add: %v", err)
168173
}
@@ -171,9 +176,8 @@ func (t *testGoRepo) clone(ctx context.Context, v, directory string) (hash strin
171176
if err != nil {
172177
return "", err
173178
}
174-
cmd = exec.CommandContext(ctx, "git", "commit", "--allow-empty-message", "--author=Joe Random <joe@example.com>",
179+
cmd = testGitCommand(ctx, directory, "commit", "--allow-empty-message", "--author=Joe Random <joe@example.com>",
175180
"--message=")
176-
cmd.Dir = directory
177181
commitTime := fmt.Sprintf("%v +0000", TestCommitTime.Unix())
178182
name := "Joe Random"
179183
email := "joe@example.com"
@@ -187,8 +191,7 @@ func (t *testGoRepo) clone(ctx context.Context, v, directory string) (hash strin
187191
}
188192
return "", fmt.Errorf("running git commit: %v", err)
189193
}
190-
cmd = exec.CommandContext(ctx, "git", "rev-parse", "HEAD")
191-
cmd.Dir = directory
194+
cmd = testGitCommand(ctx, directory, "rev-parse", "HEAD")
192195
b, err := cmd.Output()
193196
if err != nil {
194197
if ee, ok := err.(*exec.ExitError); ok {

0 commit comments

Comments
 (0)