fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

gitindex: include environ for git tests (#760)

gitindex: include environ for git tests

A recent change introduced GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM, but
ran into the footgun of unsetting the rest of the environ when cmd.Env
is non-empty. This for example broke tests for me since we didn't have
my custom $PATH set.

Instead we revert the change and make a much smaller change to just
always set the relevant environment variables.

This reverts commit ab1b8f09199ea7a731fd80876fc5b0f376ff6882.

Test Plan: go test

+13 -14
+13 -14
gitindex/index_test.go
··· 526 526 repositoryDir := t.TempDir() 527 527 528 528 // setup: initialize the repository and all of its branches 529 - runGitScript := func(t *testing.T, dir, script string) { 530 - runScript(t, dir, script, "GIT_CONFIG_GLOBAL=", "GIT_CONFIG_SYSTEM=") 531 - } 532 - runGitScript(t, repositoryDir, "git init -b master") 533 - runGitScript(t, repositoryDir, fmt.Sprintf("git config user.email %q", "you@example.com")) 534 - runGitScript(t, repositoryDir, fmt.Sprintf("git config user.name %q", "Your Name")) 529 + runScript(t, repositoryDir, "git init -b master") 530 + runScript(t, repositoryDir, fmt.Sprintf("git config user.email %q", "you@example.com")) 531 + runScript(t, repositoryDir, fmt.Sprintf("git config user.name %q", "Your Name")) 535 532 536 533 for _, b := range test.branches { 537 - runGitScript(t, repositoryDir, fmt.Sprintf("git checkout -b %q", b)) 538 - runGitScript(t, repositoryDir, fmt.Sprintf("git commit --allow-empty -m %q", "empty commit")) 534 + runScript(t, repositoryDir, fmt.Sprintf("git checkout -b %q", b)) 535 + runScript(t, repositoryDir, fmt.Sprintf("git commit --allow-empty -m %q", "empty commit")) 539 536 } 540 537 541 538 for _, step := range test.steps { ··· 545 542 546 543 hadChange := false 547 544 548 - runGitScript(t, repositoryDir, fmt.Sprintf("git checkout %q", b)) 545 + runScript(t, repositoryDir, fmt.Sprintf("git checkout %q", b)) 549 546 550 547 for _, d := range step.deletedDocuments[b] { 551 548 hadChange = true ··· 557 554 t.Fatalf("deleting file %q: %s", d.Name, err) 558 555 } 559 556 560 - runGitScript(t, repositoryDir, fmt.Sprintf("git add %q", file)) 557 + runScript(t, repositoryDir, fmt.Sprintf("git add %q", file)) 561 558 } 562 559 563 560 for _, d := range step.addedDocuments[b] { ··· 575 572 t.Fatalf("writing file %q: %s", d.Name, err) 576 573 } 577 574 578 - runGitScript(t, repositoryDir, fmt.Sprintf("git add %q", file)) 575 + runScript(t, repositoryDir, fmt.Sprintf("git add %q", file)) 579 576 } 580 577 581 578 if !hadChange { 582 579 continue 583 580 } 584 581 585 - runGitScript(t, repositoryDir, fmt.Sprintf("git commit -m %q", step.name)) 582 + runScript(t, repositoryDir, fmt.Sprintf("git commit -m %q", step.name)) 586 583 } 587 584 588 585 // setup: prepare indexOptions with given overrides ··· 755 752 } 756 753 } 757 754 758 - func runScript(t *testing.T, cwd string, script string, env ...string) { 755 + func runScript(t *testing.T, cwd string, script string) { 756 + t.Helper() 757 + 759 758 err := os.MkdirAll(cwd, 0o755) 760 759 if err != nil { 761 760 t.Fatalf("ensuring path %q exists: %s", cwd, err) ··· 763 762 764 763 cmd := exec.Command("sh", "-euxc", script) 765 764 cmd.Dir = cwd 766 - cmd.Env = env 765 + cmd.Env = append([]string{"GIT_CONFIG_GLOBAL=", "GIT_CONFIG_SYSTEM="}, os.Environ()...) 767 766 768 767 if out, err := cmd.CombinedOutput(); err != nil { 769 768 t.Fatalf("execution error: %v, output %s", err, out)