@@ -29,9 +29,9 @@ func TestExec(t *testing.T) {
29
29
func gitCommand (t * testing.T , repoPath string , args ... string ) * exec.Cmd {
30
30
t .Helper ()
31
31
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 ... )
35
35
}
36
36
37
37
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,
99
99
require .NoErrorf (t , err , "writing to file %q" , filename )
100
100
require .NoErrorf (t , f .Close (), "closing file %q" , filename )
101
101
102
- cmd := gitCommand (t , repo .Path (), "add" , relativePath )
103
- cmd .Dir = repoPath
102
+ cmd := gitCommand (t , repoPath , "add" , relativePath )
104
103
require .NoErrorf (t , cmd .Run (), "adding file %q" , relativePath )
105
104
}
106
105
@@ -257,21 +256,21 @@ func TestTaggedTags(t *testing.T) {
257
256
258
257
timestamp := time .Unix (1112911993 , 0 )
259
258
260
- cmd = gitCommand (t , repo . Path () , "commit" , "-m" , "initial" , "--allow-empty" )
259
+ cmd = gitCommand (t , path , "commit" , "-m" , "initial" , "--allow-empty" )
261
260
addAuthorInfo (cmd , & timestamp )
262
261
require .NoError (t , cmd .Run (), "creating commit" )
263
262
264
263
// The lexicographical order of these tags is important, hence
265
264
// 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" )
267
266
addAuthorInfo (cmd , & timestamp )
268
267
require .NoError (t , cmd .Run (), "creating tag 1" )
269
268
270
- cmd = gitCommand (t , repo . Path () , "tag" , "-m" , "tag 2" , "bag" , "tag" )
269
+ cmd = gitCommand (t , path , "tag" , "-m" , "tag 2" , "bag" , "tag" )
271
270
addAuthorInfo (cmd , & timestamp )
272
271
require .NoError (t , cmd .Run (), "creating tag 2" )
273
272
274
- cmd = gitCommand (t , repo . Path () , "tag" , "-m" , "tag 3" , "wag" , "bag" )
273
+ cmd = gitCommand (t , path , "tag" , "-m" , "tag 3" , "wag" , "bag" )
275
274
addAuthorInfo (cmd , & timestamp )
276
275
require .NoError (t , cmd .Run (), "creating tag 3" )
277
276
@@ -300,7 +299,7 @@ func TestFromSubdir(t *testing.T) {
300
299
301
300
addFile (t , path , repo , "subdir/file.txt" , "Hello, world!\n " )
302
301
303
- cmd = gitCommand (t , repo . Path () , "commit" , "-m" , "initial" )
302
+ cmd = gitCommand (t , path , "commit" , "-m" , "initial" )
304
303
addAuthorInfo (cmd , & timestamp )
305
304
require .NoError (t , cmd .Run (), "creating commit" )
306
305
@@ -333,7 +332,7 @@ func TestSubmodule(t *testing.T) {
333
332
addFile (t , submPath , submRepo , "submfile2.txt" , "Hello again, submodule!\n " )
334
333
addFile (t , submPath , submRepo , "submfile3.txt" , "Hello again, submodule!\n " )
335
334
336
- cmd = gitCommand (t , submRepo . Path () , "commit" , "-m" , "subm initial" )
335
+ cmd = gitCommand (t , submPath , "commit" , "-m" , "subm initial" )
337
336
addAuthorInfo (cmd , & timestamp )
338
337
require .NoError (t , cmd .Run (), "creating subm commit" )
339
338
@@ -344,16 +343,16 @@ func TestSubmodule(t *testing.T) {
344
343
require .NoError (t , err , "initializing main Repository object" )
345
344
addFile (t , mainPath , mainRepo , "mainfile.txt" , "Hello, main!\n " )
346
345
347
- cmd = gitCommand (t , mainRepo . Path () , "commit" , "-m" , "main initial" )
346
+ cmd = gitCommand (t , mainPath , "commit" , "-m" , "main initial" )
348
347
addAuthorInfo (cmd , & timestamp )
349
348
require .NoError (t , cmd .Run (), "creating main commit" )
350
349
351
350
// 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" )
353
352
cmd .Dir = mainPath
354
353
require .NoError (t , cmd .Run (), "adding submodule" )
355
354
356
- cmd = gitCommand (t , mainRepo . Path () , "commit" , "-m" , "add submodule" )
355
+ cmd = gitCommand (t , mainPath , "commit" , "-m" , "add submodule" )
357
356
addAuthorInfo (cmd , & timestamp )
358
357
require .NoError (t , cmd .Run (), "committing submodule to main" )
359
358
0 commit comments