@@ -16,8 +16,8 @@ import (
1616var info = termcolor .ColorInfo
1717
1818// EnsureUserAndEmailSetup returns the user name and email for the gitter
19- // lazily setting them if they are blank either from the given values or if they are empty
20- // using environment variables `GIT_AUTHOR_NAME` and `GIT_AUTHOR_EMAIL` or using default values
19+ // lazily setting them for git repository in dir if they are blank. The values used are either the given values,
20+ // if they are empty environment variables `GIT_AUTHOR_NAME` and `GIT_AUTHOR_EMAIL` or default values
2121func EnsureUserAndEmailSetup (gitter Interface , dir string , gitUserName string , gitUserEmail string ) (string , string , error ) {
2222 userName , _ := gitter .Command (dir , "config" , "--get" , "user.name" )
2323 userEmail , _ := gitter .Command (dir , "config" , "--get" , "user.email" )
@@ -58,8 +58,9 @@ func EnsureUserAndEmailSetup(gitter Interface, dir string, gitUserName string, g
5858 return userName , userEmail , nil
5959}
6060
61- // SetUserAndEmail sets the user and email if they have not been set
62- // Uses environment variables `GIT_AUTHOR_NAME` and `GIT_AUTHOR_EMAIL`
61+ // SetUserAndEmail sets the user and email globally if they have not been set for dir
62+ // The values used are either the given values, if they are empty environment variables `GIT_AUTHOR_NAME` and
63+ // `GIT_AUTHOR_EMAIL` or default values
6364func SetUserAndEmail (gitter Interface , dir string , gitUserName string , gitUserEmail string , assumeInCluster bool ) (string , string , error ) {
6465 userName := ""
6566 userEmail := ""
@@ -68,8 +69,8 @@ func SetUserAndEmail(gitter Interface, dir string, gitUserName string, gitUserEm
6869 userEmail = gitUserEmail
6970 } else {
7071 // lets load the current values and if they are specified lets not modify them as they are probably correct
71- userName , _ = gitter .Command (dir , "config" , "--get" , "user.name" )
72- userEmail , _ = gitter .Command (dir , "config" , "--get" , "user.email" )
72+ userName , _ = gitter .Command (dir , "config" , "--global" , "-- get" , "user.name" )
73+ userEmail , _ = gitter .Command (dir , "config" , "--global" , "-- get" , "user.email" )
7374
7475 if userName != "" && userEmail != "" {
7576 log .Logger ().Infof ("have git user name %s and email %s setup already so not going to modify them" , userName , userEmail )
@@ -91,7 +92,7 @@ func SetUserAndEmail(gitter Interface, dir string, gitUserName string, gitUserEm
9192 }
9293 }
9394 }
94- _ , err := gitter .Command (dir , "config" , "--add" , "user.name" , userName )
95+ _ , err := gitter .Command (dir , "config" , "--global" , "-- add" , "user.name" , userName )
9596 if err != nil {
9697 return userName , userEmail , fmt .Errorf ("Failed to set the git username to %s: %w" , userName , err )
9798 }
@@ -104,7 +105,7 @@ func SetUserAndEmail(gitter Interface, dir string, gitUserName string, gitUserEm
104105 userEmail = DefaultGitUserEmail
105106 }
106107 }
107- _ , err = gitter .Command (dir , "config" , "--add" , "user.email" , userEmail )
108+ _ , err = gitter .Command (dir , "config" , "--global" , "-- add" , "user.email" , userEmail )
108109 if err != nil {
109110 return userName , userEmail , fmt .Errorf ("Failed to set the git email to %s: %w" , userEmail , err )
110111 }
0 commit comments