Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions src/shared/Core/GitConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ public class GitProcessConfiguration : IGitConfiguration
{
private static readonly GitVersion TypeConfigMinVersion = new GitVersion(2, 18, 0);
private static readonly GitVersion ConfigListTypeMinVersion = new GitVersion(2, 54, 0);
private static readonly GitVersion ConfigListTypeMinVfsBase = new GitVersion(2, 53, 0);
private static readonly GitVersion ConfigListTypeMinVfsSuffix = new GitVersion(0, 1);

private readonly ITrace _trace;
private readonly GitProcess _git;
Expand All @@ -342,17 +344,43 @@ internal GitProcessConfiguration(ITrace trace, GitProcess git, bool useCache)
_trace = trace;
_git = git;

// 'git config list --type=<X>' requires Git 2.54.0+
if (useCache && git.Version < ConfigListTypeMinVersion)
// 'git config list --type=<X>' requires Git 2.54.0+,
// or microsoft/git fork 2.53.0.vfs.0.1+
if (useCache && !SupportsConfigListType(git))
{
trace.WriteLine($"Git version {git.Version} is below {ConfigListTypeMinVersion}; config cache disabled");
trace.WriteLine($"Git version {git.Version.OriginalString} does not support 'git config list --type'; config cache disabled");
useCache = false;
}

_useCache = useCache;
_cache = useCache ? new Dictionary<GitConfigurationType, ConfigCache>() : null;
}

private static bool SupportsConfigListType(GitProcess git)
{
if (git.Version >= ConfigListTypeMinVersion)
return true;

// The microsoft/git fork fast-tracked the fix into 2.53.0.vfs.0.1.
// Version strings like "2.53.0.vfs.0.1" parse as [2,53,0] because
// GitVersion stops at the non-integer "vfs" component, so we check
// the original string for the ".vfs." marker and parse the suffix.
string versionStr = git.Version.OriginalString;
if (versionStr != null)
{
int vfsIdx = versionStr.IndexOf(".vfs.");
if (vfsIdx >= 0)
{
var baseVersion = new GitVersion(versionStr.Substring(0, vfsIdx));
var vfsSuffix = new GitVersion(versionStr.Substring(vfsIdx + 5));
return baseVersion >= ConfigListTypeMinVfsBase
&& vfsSuffix >= ConfigListTypeMinVfsSuffix;
}
}

return false;
}

private void EnsureCacheLoaded(GitConfigurationType type)
{
ConfigCache cache;
Expand Down
Loading