Skip to content

Commit c7b7671

Browse files
committed
TestRefSelections: clone the test repository for each test
This eliminates the need to restore the gitconfig after each test and reduces the risk of other test crosstalk.
1 parent 27a84b9 commit c7b7671

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

git_sizer_test.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -250,23 +250,27 @@ func TestRefSelections(t *testing.T) {
250250
t.Run(
251251
p.name,
252252
func(t *testing.T) {
253-
if len(p.config) != 0 {
254-
for _, c := range p.config {
255-
cmd := testutils.GitCommand(
256-
t, path,
257-
"config", "--add", fmt.Sprintf("refgroup.mygroup.%s", c[0]), c[1],
258-
)
259-
err := cmd.Run()
260-
require.NoError(t, err)
261-
}
262-
defer func() {
263-
cmd := testutils.GitCommand(
264-
t, path, "config", "--remove-section", "refgroup.mygroup",
265-
)
266-
err := cmd.Run()
267-
require.NoError(t, err)
268-
}()
253+
clonePath, err := ioutil.TempDir("", "ref-selection")
254+
require.NoError(t, err)
255+
256+
defer os.RemoveAll(clonePath)
257+
258+
err = exec.Command(
259+
"git", "clone", "--bare", "--mirror", path, clonePath,
260+
).Run()
261+
require.NoError(t, err)
262+
263+
path := clonePath
264+
265+
for _, c := range p.config {
266+
cmd := testutils.GitCommand(
267+
t, path,
268+
"config", "--add", fmt.Sprintf("refgroup.mygroup.%s", c[0]), c[1],
269+
)
270+
err := cmd.Run()
271+
require.NoError(t, err)
269272
}
273+
270274
args := []string{"--show-refs", "--no-progress", "--json", "--json-version=2"}
271275
args = append(args, p.args...)
272276
cmd := exec.Command(executable, args...)

0 commit comments

Comments
 (0)