Skip to content

Commit 747fa41

Browse files
Merge pull request #434 from jenkins-x/partial-revert
fix: revert SetUserAndEmail to set global values
2 parents ab937c2 + 93ef029 commit 747fa41

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

pkg/gitclient/setup.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
var 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
2121
func 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
6364
func 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

Comments
 (0)