Skip to content

Commit cbbd372

Browse files
Pass --global when calling git config --get, for consistency with git config --set (#23157)
This arose out of #22451; it seems we are checking using non-global settings to see if a config value is set, in order to decide whether to call another global(-indeed) configuration command. This PR changes it so that both the check and the set are for global configuration.
1 parent f5987c2 commit cbbd372

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: modules/git/git.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func CheckGitVersionAtLeast(atLeast string) error {
312312
}
313313

314314
func configSet(key, value string) error {
315-
stdout, _, err := NewCommand(DefaultContext, "config", "--get").AddDynamicArguments(key).RunStdString(nil)
315+
stdout, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key).RunStdString(nil)
316316
if err != nil && !err.IsExitCode(1) {
317317
return fmt.Errorf("failed to get git config %s, err: %w", key, err)
318318
}
@@ -331,7 +331,7 @@ func configSet(key, value string) error {
331331
}
332332

333333
func configSetNonExist(key, value string) error {
334-
_, _, err := NewCommand(DefaultContext, "config", "--get").AddDynamicArguments(key).RunStdString(nil)
334+
_, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key).RunStdString(nil)
335335
if err == nil {
336336
// already exist
337337
return nil
@@ -349,7 +349,7 @@ func configSetNonExist(key, value string) error {
349349
}
350350

351351
func configAddNonExist(key, value string) error {
352-
_, _, err := NewCommand(DefaultContext, "config", "--get").AddDynamicArguments(key, regexp.QuoteMeta(value)).RunStdString(nil)
352+
_, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key, regexp.QuoteMeta(value)).RunStdString(nil)
353353
if err == nil {
354354
// already exist
355355
return nil
@@ -366,7 +366,7 @@ func configAddNonExist(key, value string) error {
366366
}
367367

368368
func configUnsetAll(key, value string) error {
369-
_, _, err := NewCommand(DefaultContext, "config", "--get").AddDynamicArguments(key).RunStdString(nil)
369+
_, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key).RunStdString(nil)
370370
if err == nil {
371371
// exist, need to remove
372372
_, _, err = NewCommand(DefaultContext, "config", "--global", "--unset-all").AddDynamicArguments(key, regexp.QuoteMeta(value)).RunStdString(nil)

0 commit comments

Comments
 (0)