diff --git a/src/shared/Core.Tests/SettingsTests.cs b/src/shared/Core.Tests/SettingsTests.cs index c93685e75..24a7438b7 100644 --- a/src/shared/Core.Tests/SettingsTests.cs +++ b/src/shared/Core.Tests/SettingsTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Net; using GitCredentialManager.Tests.Objects; diff --git a/src/shared/Core/Interop/Windows/WindowsSettings.cs b/src/shared/Core/Interop/Windows/WindowsSettings.cs index f6e92eca9..abdd9ee0e 100644 --- a/src/shared/Core/Interop/Windows/WindowsSettings.cs +++ b/src/shared/Core/Interop/Windows/WindowsSettings.cs @@ -17,7 +17,7 @@ public WindowsSettings(IEnvironment environment, IGit git, ITrace trace) PlatformUtils.EnsureWindows(); } - protected override bool TryGetExternalDefault(string section, string property, out string value) + protected override bool TryGetExternalDefault(string section, string scope, string property, out string value) { value = null; @@ -32,7 +32,10 @@ protected override bool TryGetExternalDefault(string section, string property, o return false; } - string name = $"{section}.{property}"; + string name = string.IsNullOrWhiteSpace(scope) + ? $"{section}.{property}" + : $"{section}.{scope}.{property}"; + object registryValue = configKey.GetValue(name); if (registryValue is null) { @@ -46,7 +49,7 @@ protected override bool TryGetExternalDefault(string section, string property, o return true; } #else - return base.TryGetExternalDefault(section, property, out value); + return base.TryGetExternalDefault(section, scope, property, out value); #endif } } diff --git a/src/shared/Core/Settings.cs b/src/shared/Core/Settings.cs index 3eafa0baa..55069d63b 100644 --- a/src/shared/Core/Settings.cs +++ b/src/shared/Core/Settings.cs @@ -408,6 +408,12 @@ public IEnumerable GetSettingValues(string envarName, string section, st { yield return value; } + + // Check for an externally specified default value + if (TryGetExternalDefault(section, scope, property, out value)) + { + yield return value; + } } } @@ -423,10 +429,10 @@ public IEnumerable GetSettingValues(string envarName, string section, st yield return value; } - // Check for an externally specified default value - if (TryGetExternalDefault(section, property, out string defaultValue)) + // Check for an externally specified default value without a scope + if (TryGetExternalDefault(section, null, property, out value)) { - yield return defaultValue; + yield return value; } } } @@ -436,10 +442,11 @@ public IEnumerable GetSettingValues(string envarName, string section, st /// This may come from external policies or the Operating System. /// /// Configuration section name. + /// Optional configuration scope. /// Configuration property name. /// Value of the configuration setting, or null. /// True if a default setting has been set, false otherwise. - protected virtual bool TryGetExternalDefault(string section, string property, out string value) + protected virtual bool TryGetExternalDefault(string section, string scope, string property, out string value) { value = null; return false;