Skip to content

Commit eb1b073

Browse files
authored
Merge pull request #35 from xmudrii/improve-check-gitconfig
Minor improvements to CheckGitConfigExists
2 parents e0046a0 + 3250ae8 commit eb1b073

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

mage/git.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const (
2929
gitConfigEmailValue = "nobody@k8s.io"
3030
)
3131

32-
func CheckGitConfigExists() (bool, error) {
32+
func CheckGitConfigExists() bool {
3333
userName := command.New(
3434
"git",
3535
"config",
@@ -38,9 +38,11 @@ func CheckGitConfigExists() (bool, error) {
3838
gitConfigNameKey,
3939
)
4040

41-
stream, err := userName.RunSuccessOutput()
41+
stream, err := userName.RunSilentSuccessOutput()
4242
if err != nil || stream.OutputTrimNL() == "" {
43-
return false, nil
43+
// NB: We're intentionally ignoring the error here because 'git config'
44+
// returns an error (result code -1) if the config doesn't exist.
45+
return false
4446
}
4547

4648
userEmail := command.New(
@@ -51,19 +53,18 @@ func CheckGitConfigExists() (bool, error) {
5153
gitConfigEmailKey,
5254
)
5355

54-
stream, err = userEmail.RunSuccessOutput()
56+
stream, err = userEmail.RunSilentSuccessOutput()
5557
if err != nil || stream.OutputTrimNL() == "" {
56-
return false, nil
58+
// NB: We're intentionally ignoring the error here because 'git config'
59+
// returns an error (result code -1) if the config doesn't exist.
60+
return false
5761
}
5862

59-
return true, nil
63+
return true
6064
}
6165

6266
func EnsureGitConfig() error {
63-
exists, err := CheckGitConfigExists()
64-
if err != nil {
65-
return errors.Wrap(err, "ensuring git config")
66-
}
67+
exists := CheckGitConfigExists()
6768
if exists {
6869
return nil
6970
}

0 commit comments

Comments
 (0)