Skip to content

Commit 135722a

Browse files
committed
Remove dependency on installed git
By reading the global .gitconfig directly using the compatible DotNetConfig, we can remove this dependency which was just for a couple of global settings (the default credential namespace, credential store and an MS Auth setting). Fixes #125 for real.
1 parent 81612d7 commit 135722a

File tree

4 files changed

+76
-15
lines changed

4 files changed

+76
-15
lines changed

.github/workflows/build.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ on:
2020
env:
2121
DOTNET_NOLOGO: true
2222
SLEET_CONNECTION: ${{ secrets.SLEET_CONNECTION }}
23+
MSBUILDTERMINALLOGGER: auto
24+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
25+
Configuration: ${{ github.event.inputs.configuration || 'Release' }}
26+
SLEET_FEED_URL: ${{ vars.SLEET_FEED_URL }}
2327

2428
defaults:
2529
run:
@@ -98,8 +102,16 @@ jobs:
98102
name: pkg
99103
path: bin
100104

105+
- name: ⚙ dotnet
106+
uses: devlooped/actions-dotnet-env@v1
107+
108+
- name: 🙏 build
109+
run: dotnet build
110+
101111
- name: 🧪 test
102-
run: dotnet test --nologo -bl --logger:"console;verbosity=normal"
112+
run: |
113+
dotnet tool update -g dotnet-retest
114+
dotnet retest -- --no-build
103115
104116
- name: 🐛 logs
105117
uses: actions/upload-artifact@v4

src/CredentialManager/CredentialManager.cs

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
using System;
22
using 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

49
namespace 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;

src/CredentialManager/CredentialManager.csproj

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20+
<PackageReference Include="DotNetConfig" Version="1.2.0" />
2021
<PackageReference Include="NuGetizer" Version="1.2.3" PrivateAssets="all" />
2122
<PackageReference Include="ILRepack" Version="2.0.33" Pack="false" />
2223
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="8.0.0" />
@@ -28,11 +29,7 @@
2829
<ProjectReference Include="..\Core\Core.csproj" Pack="false" />
2930
</ItemGroup>
3031

31-
<Target Name="ILRepack" BeforeTargets="CopyFilesToOutputDirectory"
32-
Inputs="@(IntermediateAssembly -> '%(FullPath)')"
33-
Outputs="$(IntermediateOutputPath)ilrepack.txt"
34-
Returns="@(MergedAssemblies)"
35-
Condition="$(OS) == 'WINDOWS_NT' And Exists(@(IntermediateAssembly -&gt; '%(FullPath)'))">
32+
<Target Name="ILRepack" BeforeTargets="CopyFilesToOutputDirectory" Inputs="@(IntermediateAssembly -> '%(FullPath)')" Outputs="$(IntermediateOutputPath)ilrepack.txt" Returns="@(MergedAssemblies)" Condition="$(OS) == 'WINDOWS_NT' And Exists(@(IntermediateAssembly -> '%(FullPath)'))">
3633
<Message Text="Repacking" Importance="high" />
3734
<ItemGroup>
3835
<MergedAssemblies Include="@(ReferencePath)" Condition="'%(Extension)' == '.dll' And $([MSBuild]::ValueOrDefault('%(FileName)', '')) == 'Core'" />
@@ -42,7 +39,7 @@
4239
<ILRepackArgs>$(ILRepackArgs) "@(IntermediateAssembly -> '%(FullPath)')"</ILRepackArgs>
4340
<ILRepackArgs>$(ILRepackArgs) @(MergedAssemblies -> '"%(FullPath)"', ' ')</ILRepackArgs>
4441
</PropertyGroup>
45-
<Exec Command='"$(ILRepack)" /internalize:exclude.txt $(ILRepackArgs)' StandardErrorImportance="high" StandardOutputImportance="low" ConsoleToMSBuild="true" ContinueOnError="true">
42+
<Exec Command="&quot;$(ILRepack)&quot; /internalize:exclude.txt $(ILRepackArgs)" StandardErrorImportance="high" StandardOutputImportance="low" ConsoleToMSBuild="true" ContinueOnError="true">
4643
<Output TaskParameter="ConsoleOutput" PropertyName="ILRepackOutput" />
4744
<Output TaskParameter="ExitCode" PropertyName="ExitCode" />
4845
</Exec>
@@ -54,8 +51,7 @@
5451
<MergedAssembliesToRemove Include="@(MergedAssemblies)" />
5552
<MergedAssembliesToRemove Remove="@(ReferenceToPreserve)" />
5653
</ItemGroup>
57-
<Delete Files="@(MergedAssembliesToRemove -> '$(MSBuildProjectDirectory)\$(OutputPath)%(Filename)%(Extension)')"
58-
Condition="Exists('$(MSBuildProjectDirectory)\$(OutputPath)%(Filename)%(Extension)')" />
54+
<Delete Files="@(MergedAssembliesToRemove -> '$(MSBuildProjectDirectory)\$(OutputPath)%(Filename)%(Extension)')" Condition="Exists('$(MSBuildProjectDirectory)\$(OutputPath)%(Filename)%(Extension)')" />
5955
</Target>
6056

6157
</Project>

src/Tests/Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
1616
<PackageReference Include="xunit" Version="2.5.3" />
1717
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
18-
<PackageReference Include="Devlooped.CredentialManager" Version="42.*" Condition="!$(CI)" />
18+
<PackageReference Include="Devlooped.CredentialManager" Version="42.42.42-main.*" Condition="!$(CI)" />
1919
<PackageReference Include="Devlooped.CredentialManager" Version="$(Version)" Condition="$(CI) And Exists('$(PackageOutputPath)')" />
2020
</ItemGroup>
2121

0 commit comments

Comments
 (0)