Skip to content

Commit 315652f

Browse files
committed
Avoid relying on global gitconfig in tests
Signed-off-by: Fredrik Sommar <[email protected]>
1 parent c25345f commit 315652f

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

internal/gitutil/gitutil.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ func (g *GitLocalRunner) RunVerbose(ctx context.Context, command string, args ..
9797
func (g *GitLocalRunner) run(ctx context.Context, verbose bool, command string, args ...string) (RunResult, error) {
9898
const op errors.Op = "gitutil.run"
9999

100-
fullArgs := append([]string{command}, args...)
100+
fullArgs := append(
101+
[]string{"-c", "user.name=Kpt", "-c", "[email protected]", command},
102+
args...,
103+
)
101104
cmd := exec.CommandContext(ctx, g.gitPath, fullArgs...)
102105
cmd.Dir = g.Dir
103106
// Disable git prompting the user for credentials.

internal/testutil/testutil.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,14 @@ func replaceData(repo, data string) error {
732732
}
733733

734734
func commit(repo, message string) (string, error) {
735-
cmd := exec.Command("git", "commit", "-m", message, "--allow-empty")
735+
cmd := exec.Command(
736+
"git",
737+
"-c", "user.name=Kpt",
738+
739+
"commit",
740+
"-m", message,
741+
"--allow-empty",
742+
)
736743
cmd.Dir = repo
737744
stdoutStderr, err := cmd.CombinedOutput()
738745
if err != nil {
@@ -749,7 +756,12 @@ func commit(repo, message string) (string, error) {
749756
}
750757

751758
func tag(repo, tag string) error {
752-
cmd := exec.Command("git", "tag", tag)
759+
cmd := exec.Command(
760+
"git",
761+
"-c", "user.name=Kpt",
762+
763+
"tag", tag,
764+
)
753765
cmd.Dir = repo
754766
b, err := cmd.Output()
755767
if err != nil {

0 commit comments

Comments
 (0)