11using System ;
22using System . Collections . Generic ;
3+ using System . IO ;
4+ using System . Runtime . InteropServices ;
5+ using DotNetConfig ;
6+ using KnownEnvars = GitCredentialManager . Constants . EnvironmentVariables ;
7+ using KnownGitCfg = GitCredentialManager . Constants . GitConfiguration ;
38
49namespace GitCredentialManager ;
510
@@ -68,8 +73,60 @@ class CommandContextWrapper(CommandContext context, string? @namespace) : IComma
6873
6974 class SettingsWrapper ( ISettings settings , string ? @namespace ) : ISettings
7075 {
76+ static readonly Config gitconfig ;
77+
78+ static SettingsWrapper ( )
79+ {
80+ string homeDir ;
81+
82+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
83+ {
84+ homeDir = Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ;
85+ }
86+ else
87+ {
88+ // On Linux/Mac it's $HOME
89+ homeDir = Environment . GetEnvironmentVariable ( "HOME" )
90+ ?? Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ;
91+ }
92+
93+ gitconfig = Config . Build ( Path . Combine ( homeDir , ".gitconfig" ) ) ;
94+ }
95+
96+ static bool TryGetWrappedSetting ( string envarName , string section , string property , out string value )
97+ {
98+ if ( envarName != null && Environment . GetEnvironmentVariable ( envarName ) is { Length : > 0 } envvar )
99+ {
100+ value = envvar ;
101+ return true ;
102+ }
103+
104+ return gitconfig . TryGetString ( section , property , out value ) ;
105+ }
106+
71107 // Overriden namespace to scope credential operations.
72- public string CredentialNamespace => @namespace ?? settings . CredentialNamespace ;
108+ public string CredentialNamespace => @namespace ?? (
109+ TryGetWrappedSetting ( KnownEnvars . GcmCredNamespace ,
110+ KnownGitCfg . Credential . SectionName , KnownGitCfg . Credential . CredNamespace ,
111+ out var ns ) ? ns : Constants . DefaultCredentialNamespace ) ;
112+
113+ public string CredentialBackingStore =>
114+ TryGetWrappedSetting (
115+ KnownEnvars . GcmCredentialStore ,
116+ KnownGitCfg . Credential . SectionName ,
117+ KnownGitCfg . Credential . CredentialStore ,
118+ out string credStore )
119+ ? credStore
120+ : null ! ;
121+
122+ public bool UseMsAuthDefaultAccount =>
123+ TryGetWrappedSetting (
124+ KnownEnvars . MsAuthUseDefaultAccount ,
125+ KnownGitCfg . Credential . SectionName ,
126+ KnownGitCfg . Credential . MsAuthUseDefaultAccount ,
127+ out string str )
128+ ? str . IsTruthy ( )
129+ : PlatformUtils . IsDevBox ( ) ; // default to true in DevBox environment
73130
74131 #region pass-through impl.
75132
@@ -99,8 +156,6 @@ class SettingsWrapper(ISettings settings, string? @namespace) : ISettings
99156
100157 public string ParentWindowId => settings . ParentWindowId ;
101158
102- public string CredentialBackingStore => settings . CredentialBackingStore ;
103-
104159 public string CustomCertificateBundlePath => settings . CustomCertificateBundlePath ;
105160
106161 public string CustomCookieFilePath => settings . CustomCookieFilePath ;
@@ -111,8 +166,6 @@ class SettingsWrapper(ISettings settings, string? @namespace) : ISettings
111166
112167 public int AutoDetectProviderTimeout => settings . AutoDetectProviderTimeout ;
113168
114- public bool UseMsAuthDefaultAccount => settings . UseMsAuthDefaultAccount ;
115-
116169 public bool UseSoftwareRendering => settings . UseSoftwareRendering ;
117170
118171 public bool AllowUnsafeRemotes => settings . AllowUnsafeRemotes ;
0 commit comments