Skip to content

Commit c552709

Browse files
committed
azrepos-cfg: only clear useHttpPath on Windows if no manager-core
Only clear the useHttpPath=true option on calls to unconfigure if the "manager-core" option is not present and we're in the system config on a Windows platform. This would be the case for the bundled GCM Core in Git for Windows, which we would break by removing this option.
1 parent 8ce1ed2 commit c552709

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

src/shared/Microsoft.AzureRepos.Tests/AzureReposHostProviderTests.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using Microsoft.Git.CredentialManager;
77
using Microsoft.Git.CredentialManager.Authentication;
8+
using Microsoft.Git.CredentialManager.Tests;
89
using Microsoft.Git.CredentialManager.Tests.Objects;
910
using Moq;
1011
using Xunit;
@@ -14,6 +15,8 @@ namespace Microsoft.AzureRepos.Tests
1415
{
1516
public class AzureReposHostProviderTests
1617
{
18+
private static readonly string HelperKey =
19+
$"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}";
1720
private static readonly string AzDevUseHttpPathKey =
1821
$"{Constants.GitConfiguration.Credential.SectionName}.https://dev.azure.com.{Constants.GitConfiguration.Credential.UseHttpPath}";
1922

@@ -222,7 +225,6 @@ public async Task AzureReposHostProvider_ConfigureAsync_UseHttpPathUnset_SetsUse
222225
Assert.Equal("true", actualValues[0]);
223226
}
224227

225-
226228
[Fact]
227229
public async Task AzureReposHostProvider_UnconfigureAsync_UseHttpPathSet_RemovesEntry()
228230
{
@@ -235,5 +237,48 @@ public async Task AzureReposHostProvider_UnconfigureAsync_UseHttpPathSet_Removes
235237

236238
Assert.Empty(context.Git.GlobalConfiguration.Dictionary);
237239
}
240+
241+
[PlatformFact(Platforms.Windows)]
242+
public async Task AzureReposHostProvider_UnconfigureAsync_System_Windows_UseHttpPathSetAndManagerCoreHelper_DoesNotRemoveEntry()
243+
{
244+
var context = new TestCommandContext();
245+
var provider = new AzureReposHostProvider(context);
246+
247+
context.Git.SystemConfiguration.Dictionary[HelperKey] = new List<string> {"manager-core"};
248+
context.Git.SystemConfiguration.Dictionary[AzDevUseHttpPathKey] = new List<string> {"true"};
249+
250+
await provider.UnconfigureAsync(ConfigurationTarget.System);
251+
252+
Assert.True(context.Git.SystemConfiguration.Dictionary.TryGetValue(AzDevUseHttpPathKey, out IList<string> actualValues));
253+
Assert.Single(actualValues);
254+
Assert.Equal("true", actualValues[0]);
255+
}
256+
257+
[PlatformFact(Platforms.Windows)]
258+
public async Task AzureReposHostProvider_UnconfigureAsync_System_Windows_UseHttpPathSetNoManagerCoreHelper_RemovesEntry()
259+
{
260+
var context = new TestCommandContext();
261+
var provider = new AzureReposHostProvider(context);
262+
263+
context.Git.SystemConfiguration.Dictionary[AzDevUseHttpPathKey] = new List<string> {"true"};
264+
265+
await provider.UnconfigureAsync(ConfigurationTarget.System);
266+
267+
Assert.Empty(context.Git.SystemConfiguration.Dictionary);
268+
}
269+
270+
[PlatformFact(Platforms.Windows)]
271+
public async Task AzureReposHostProvider_UnconfigureAsync_User_Windows_UseHttpPathSetAndManagerCoreHelper_RemovesEntry()
272+
{
273+
var context = new TestCommandContext();
274+
var provider = new AzureReposHostProvider(context);
275+
276+
context.Git.GlobalConfiguration.Dictionary[HelperKey] = new List<string> {"manager-core"};
277+
context.Git.GlobalConfiguration.Dictionary[AzDevUseHttpPathKey] = new List<string> {"true"};
278+
279+
await provider.UnconfigureAsync(ConfigurationTarget.User);
280+
281+
Assert.False(context.Git.GlobalConfiguration.Dictionary.TryGetValue(AzDevUseHttpPathKey, out _));
282+
}
238283
}
239284
}

src/shared/Microsoft.AzureRepos/AzureReposHostProvider.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33
using System;
44
using System.Collections.Generic;
5+
using System.Linq;
56
using System.Threading.Tasks;
67
using Microsoft.Git.CredentialManager;
78
using Microsoft.Git.CredentialManager.Authentication;
@@ -275,6 +276,7 @@ public Task ConfigureAsync(ConfigurationTarget target)
275276

276277
public Task UnconfigureAsync(ConfigurationTarget target)
277278
{
279+
string helperKey = $"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}";
278280
string useHttpPathKey = $"{KnownGitCfg.Credential.SectionName}.https://dev.azure.com.{KnownGitCfg.Credential.UseHttpPath}";
279281

280282
_context.Trace.WriteLine("Clearing Git configuration 'credential.useHttpPath' for https://dev.azure.com...");
@@ -284,7 +286,14 @@ public Task UnconfigureAsync(ConfigurationTarget target)
284286
: GitConfigurationLevel.Global;
285287

286288
IGitConfiguration targetConfig = _context.Git.GetConfiguration(configurationLevel);
287-
targetConfig.Unset(useHttpPathKey);
289+
290+
// On Windows, if there is a "manager-core" entry remaining in the system config then we must not clear
291+
// the useHttpPath option otherwise this would break the bundled version of GCM Core in Git for Windows.
292+
if (!PlatformUtils.IsWindows() || target != ConfigurationTarget.System ||
293+
targetConfig.GetAll(helperKey).All(x => !string.Equals(x, "manager-core")))
294+
{
295+
targetConfig.Unset(useHttpPathKey);
296+
}
288297

289298
return Task.CompletedTask;
290299
}

0 commit comments

Comments
 (0)