Skip to content

Commit

Permalink
Tests: disable global git configs (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
camdencheek authored Apr 10, 2024
1 parent c39011a commit ab1b8f0
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions gitindex/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,16 @@ func TestIndexDeltaBasic(t *testing.T) {
repositoryDir := t.TempDir()

// setup: initialize the repository and all of its branches
runScript(t, repositoryDir, "git init -b master")
runScript(t, repositoryDir, fmt.Sprintf("git config user.email %q", "[email protected]"))
runScript(t, repositoryDir, fmt.Sprintf("git config user.name %q", "Your Name"))
runGitScript := func(t *testing.T, dir, script string) {
runScript(t, dir, script, "GIT_CONFIG_GLOBAL=", "GIT_CONFIG_SYSTEM=")
}
runGitScript(t, repositoryDir, "git init -b master")
runGitScript(t, repositoryDir, fmt.Sprintf("git config user.email %q", "[email protected]"))
runGitScript(t, repositoryDir, fmt.Sprintf("git config user.name %q", "Your Name"))

for _, b := range test.branches {
runScript(t, repositoryDir, fmt.Sprintf("git checkout -b %q", b))
runScript(t, repositoryDir, fmt.Sprintf("git commit --allow-empty -m %q", "empty commit"))
runGitScript(t, repositoryDir, fmt.Sprintf("git checkout -b %q", b))
runGitScript(t, repositoryDir, fmt.Sprintf("git commit --allow-empty -m %q", "empty commit"))
}

for _, step := range test.steps {
Expand All @@ -542,7 +545,7 @@ func TestIndexDeltaBasic(t *testing.T) {

hadChange := false

runScript(t, repositoryDir, fmt.Sprintf("git checkout %q", b))
runGitScript(t, repositoryDir, fmt.Sprintf("git checkout %q", b))

for _, d := range step.deletedDocuments[b] {
hadChange = true
Expand All @@ -554,7 +557,7 @@ func TestIndexDeltaBasic(t *testing.T) {
t.Fatalf("deleting file %q: %s", d.Name, err)
}

runScript(t, repositoryDir, fmt.Sprintf("git add %q", file))
runGitScript(t, repositoryDir, fmt.Sprintf("git add %q", file))
}

for _, d := range step.addedDocuments[b] {
Expand All @@ -572,14 +575,14 @@ func TestIndexDeltaBasic(t *testing.T) {
t.Fatalf("writing file %q: %s", d.Name, err)
}

runScript(t, repositoryDir, fmt.Sprintf("git add %q", file))
runGitScript(t, repositoryDir, fmt.Sprintf("git add %q", file))
}

if !hadChange {
continue
}

runScript(t, repositoryDir, fmt.Sprintf("git commit -m %q", step.name))
runGitScript(t, repositoryDir, fmt.Sprintf("git commit -m %q", step.name))
}

// setup: prepare indexOptions with given overrides
Expand Down Expand Up @@ -752,14 +755,15 @@ func TestRepoPathRanks(t *testing.T) {
}
}

func runScript(t *testing.T, cwd string, script string) {
func runScript(t *testing.T, cwd string, script string, env ...string) {
err := os.MkdirAll(cwd, 0o755)
if err != nil {
t.Fatalf("ensuring path %q exists: %s", cwd, err)
}

cmd := exec.Command("sh", "-euxc", script)
cmd.Dir = cwd
cmd.Env = env

if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("execution error: %v, output %s", err, out)
Expand Down

0 comments on commit ab1b8f0

Please sign in to comment.