@@ -21,7 +21,7 @@ import (
2121 "testing"
2222
2323 "github.com/go-git/go-git/v5"
24- gogitConfig "github.com/go-git/go-git/v5/config"
24+ goGitConfig "github.com/go-git/go-git/v5/config"
2525 "github.com/go-git/go-git/v5/plumbing/object"
2626 "github.com/google/go-cmp/cmp"
2727)
@@ -367,15 +367,33 @@ func TestAddAll(t *testing.T) {
367367
368368func TestCommit (t * testing.T ) {
369369 t .Parallel ()
370+ name ,
email := "tester" ,
"[email protected] " 370371 // setupRepo is a helper to create a repository with an initial commit.
371372 setupRepo := func (t * testing.T ) * LocalRepository {
372373 t .Helper ()
373374 dir := t .TempDir ()
374- gogitRepo , err := git .PlainInit (dir , false )
375+ goGitRepo , err := git .PlainInit (dir , false )
375376 if err != nil {
376377 t .Fatalf ("git.PlainInit failed: %v" , err )
377378 }
378- w , err := gogitRepo .Worktree ()
379+
380+ author := struct {
381+ Name string
382+ Email string
383+ }{
384+ Name : name ,
385+ Email : email ,
386+ }
387+ config , err := goGitRepo .Config ()
388+ if err != nil {
389+ t .Fatalf ("gitRepo.Config failed: %v" , err )
390+ }
391+ config .User = author
392+ if err := goGitRepo .SetConfig (config ); err != nil {
393+ t .Fatalf ("gitRepo.SetConfig failed: %v" , err )
394+ }
395+
396+ w , err := goGitRepo .Worktree ()
379397 if err != nil {
380398 t .Fatalf ("Worktree() failed: %v" , err )
381399 }
@@ -385,15 +403,13 @@ func TestCommit(t *testing.T) {
385403 }); err != nil {
386404 t .Fatalf ("initial commit failed: %v" , err )
387405 }
388- return & LocalRepository {Dir : dir , repo : gogitRepo }
406+ return & LocalRepository {Dir : dir , repo : goGitRepo }
389407 }
390408
391409 for _ , tc := range []struct {
392410 name string
393411 setup func (t * testing.T ) * LocalRepository
394412 commitMsg string
395- userName string
396- userEmail string
397413 wantErr bool
398414 wantErrMsg string
399415 check func (t * testing.T , repo * LocalRepository , commitMsg string )
@@ -417,8 +433,6 @@ func TestCommit(t *testing.T) {
417433 return repo
418434 },
419435 commitMsg : "feat: add new file" ,
420- userName : "tester" ,
421- 422436 check : func (t * testing.T , repo * LocalRepository , commitMsg string ) {
423437 head , err := repo .repo .Head ()
424438 if err != nil {
@@ -446,8 +460,6 @@ func TestCommit(t *testing.T) {
446460 return setupRepo (t )
447461 },
448462 commitMsg : "no-op" ,
449- userName : "tester" ,
450- 451463 wantErr : true ,
452464 wantErrMsg : "no modifications to commit" ,
453465 },
@@ -456,15 +468,13 @@ func TestCommit(t *testing.T) {
456468 setup : func (t * testing.T ) * LocalRepository {
457469 dir := t .TempDir ()
458470 // Create a bare repository which has no worktree.
459- gogitRepo , err := git .PlainInit (dir , true )
471+ goGitRepo , err := git .PlainInit (dir , true )
460472 if err != nil {
461473 t .Fatalf ("git.PlainInit failed: %v" , err )
462474 }
463- return & LocalRepository {Dir : dir , repo : gogitRepo }
475+ return & LocalRepository {Dir : dir , repo : goGitRepo }
464476 },
465477 commitMsg : "any message" ,
466- userName : "tester" ,
467- 468478 wantErr : true ,
469479 wantErrMsg : "worktree not available" ,
470480 },
@@ -497,8 +507,6 @@ func TestCommit(t *testing.T) {
497507 return repo
498508 },
499509 commitMsg : "any message" ,
500- userName : "tester" ,
501- 502510 wantErr : true ,
503511 wantErrMsg : "permission denied" ,
504512 },
@@ -507,7 +515,7 @@ func TestCommit(t *testing.T) {
507515 t .Parallel ()
508516 repo := tc .setup (t )
509517
510- err := repo .Commit (tc .commitMsg , tc . userName , tc . userEmail )
518+ err := repo .Commit (tc .commitMsg )
511519
512520 if tc .wantErr {
513521 if err == nil {
@@ -564,7 +572,7 @@ func TestRemotes(t *testing.T) {
564572 }
565573
566574 for name , urls := range tt .setupRemotes {
567- if _ , err := gogitRepo .CreateRemote (& gogitConfig .RemoteConfig {
575+ if _ , err := gogitRepo .CreateRemote (& goGitConfig .RemoteConfig {
568576 Name : name ,
569577 URLs : urls ,
570578 }); err != nil {
0 commit comments