Skip to content

Commit 5dbc258

Browse files
committed
gitCommand: take the path of there repo, not the GIT_DIR, as arg
1 parent 72f7a67 commit 5dbc258

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

git_sizer_test.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ func TestExec(t *testing.T) {
2929
func gitCommand(t *testing.T, repoPath string, args ...string) *exec.Cmd {
3030
t.Helper()
3131

32-
cmd := exec.Command("git", args...)
33-
cmd.Env = append(os.Environ(), "GIT_DIR="+repoPath)
34-
return cmd
32+
gitArgs := []string{"-C", repoPath}
33+
gitArgs = append(gitArgs, args...)
34+
return exec.Command("git", gitArgs...)
3535
}
3636

3737
func updateRef(t *testing.T, repoPath string, refname string, oid git.OID) error {
@@ -99,8 +99,7 @@ func addFile(t *testing.T, repoPath string, repo *git.Repository, relativePath,
9999
require.NoErrorf(t, err, "writing to file %q", filename)
100100
require.NoErrorf(t, f.Close(), "closing file %q", filename)
101101

102-
cmd := gitCommand(t, repo.Path(), "add", relativePath)
103-
cmd.Dir = repoPath
102+
cmd := gitCommand(t, repoPath, "add", relativePath)
104103
require.NoErrorf(t, cmd.Run(), "adding file %q", relativePath)
105104
}
106105

@@ -257,21 +256,21 @@ func TestTaggedTags(t *testing.T) {
257256

258257
timestamp := time.Unix(1112911993, 0)
259258

260-
cmd = gitCommand(t, repo.Path(), "commit", "-m", "initial", "--allow-empty")
259+
cmd = gitCommand(t, path, "commit", "-m", "initial", "--allow-empty")
261260
addAuthorInfo(cmd, &timestamp)
262261
require.NoError(t, cmd.Run(), "creating commit")
263262

264263
// The lexicographical order of these tags is important, hence
265264
// their strange names.
266-
cmd = gitCommand(t, repo.Path(), "tag", "-m", "tag 1", "tag", "master")
265+
cmd = gitCommand(t, path, "tag", "-m", "tag 1", "tag", "master")
267266
addAuthorInfo(cmd, &timestamp)
268267
require.NoError(t, cmd.Run(), "creating tag 1")
269268

270-
cmd = gitCommand(t, repo.Path(), "tag", "-m", "tag 2", "bag", "tag")
269+
cmd = gitCommand(t, path, "tag", "-m", "tag 2", "bag", "tag")
271270
addAuthorInfo(cmd, &timestamp)
272271
require.NoError(t, cmd.Run(), "creating tag 2")
273272

274-
cmd = gitCommand(t, repo.Path(), "tag", "-m", "tag 3", "wag", "bag")
273+
cmd = gitCommand(t, path, "tag", "-m", "tag 3", "wag", "bag")
275274
addAuthorInfo(cmd, &timestamp)
276275
require.NoError(t, cmd.Run(), "creating tag 3")
277276

@@ -300,7 +299,7 @@ func TestFromSubdir(t *testing.T) {
300299

301300
addFile(t, path, repo, "subdir/file.txt", "Hello, world!\n")
302301

303-
cmd = gitCommand(t, repo.Path(), "commit", "-m", "initial")
302+
cmd = gitCommand(t, path, "commit", "-m", "initial")
304303
addAuthorInfo(cmd, &timestamp)
305304
require.NoError(t, cmd.Run(), "creating commit")
306305

@@ -333,7 +332,7 @@ func TestSubmodule(t *testing.T) {
333332
addFile(t, submPath, submRepo, "submfile2.txt", "Hello again, submodule!\n")
334333
addFile(t, submPath, submRepo, "submfile3.txt", "Hello again, submodule!\n")
335334

336-
cmd = gitCommand(t, submRepo.Path(), "commit", "-m", "subm initial")
335+
cmd = gitCommand(t, submPath, "commit", "-m", "subm initial")
337336
addAuthorInfo(cmd, &timestamp)
338337
require.NoError(t, cmd.Run(), "creating subm commit")
339338

@@ -344,16 +343,16 @@ func TestSubmodule(t *testing.T) {
344343
require.NoError(t, err, "initializing main Repository object")
345344
addFile(t, mainPath, mainRepo, "mainfile.txt", "Hello, main!\n")
346345

347-
cmd = gitCommand(t, mainRepo.Path(), "commit", "-m", "main initial")
346+
cmd = gitCommand(t, mainPath, "commit", "-m", "main initial")
348347
addAuthorInfo(cmd, &timestamp)
349348
require.NoError(t, cmd.Run(), "creating main commit")
350349

351350
// Make subm a submodule of main:
352-
cmd = gitCommand(t, mainRepo.Path(), "submodule", "add", submPath, "sub")
351+
cmd = gitCommand(t, mainPath, "submodule", "add", submPath, "sub")
353352
cmd.Dir = mainPath
354353
require.NoError(t, cmd.Run(), "adding submodule")
355354

356-
cmd = gitCommand(t, mainRepo.Path(), "commit", "-m", "add submodule")
355+
cmd = gitCommand(t, mainPath, "commit", "-m", "add submodule")
357356
addAuthorInfo(cmd, &timestamp)
358357
require.NoError(t, cmd.Run(), "committing submodule to main")
359358

0 commit comments

Comments
 (0)