Skip to content

Commit 0fea6fa

Browse files
feat: Gate config cache on Git 2.54.0+ version check
Context: The config cache uses 'git config list --type=<X>' to load type-specific caches (raw, bool, path). The --type flag for the 'list' subcommand requires a fix queued for the Git 2.54.0 release. On Git 2.53 and earlier, the command succeeds but silently ignores the --type parameter, returning raw values instead of canonicalized ones. This means bool caches would contain 'yes'/'on' instead of 'true', and path caches would contain unexpanded '~/...' instead of absolute paths. Justification: Because the command exits 0 on older Git, the cache appears to load successfully and the fallback paths never trigger. This makes the bug silent and data-dependent: lookups work for values that happen to already be in canonical form but return wrong results for others. A version gate is the only reliable way to avoid this. The check is in the constructor body rather than the constructor chain so we can log a trace message when caching is disabled. The explicit useCache parameter is preserved for tests that need to control caching behavior independently of version. Implementation: Added ConfigListTypeMinVersion constant (2.54.0) and a version comparison in the GitProcessConfiguration constructor. When useCache is requested but git.Version is below the minimum, the constructor overrides useCache to false and emits a trace line. All existing fallback paths continue to work unchanged for users on older Git, who will benefit from the cache automatically once they upgrade. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c7687ad commit 0fea6fa

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/shared/Core/GitConfiguration.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ public void Clear()
343343
public class GitProcessConfiguration : IGitConfiguration
344344
{
345345
private static readonly GitVersion TypeConfigMinVersion = new GitVersion(2, 18, 0);
346+
private static readonly GitVersion ConfigListTypeMinVersion = new GitVersion(2, 54, 0);
346347

347348
private readonly ITrace _trace;
348349
private readonly GitProcess _git;
@@ -360,6 +361,14 @@ internal GitProcessConfiguration(ITrace trace, GitProcess git, bool useCache)
360361

361362
_trace = trace;
362363
_git = git;
364+
365+
// 'git config list --type=<X>' requires Git 2.54.0+
366+
if (useCache && git.Version < ConfigListTypeMinVersion)
367+
{
368+
trace.WriteLine($"Git version {git.Version} is below {ConfigListTypeMinVersion}; config cache disabled");
369+
useCache = false;
370+
}
371+
363372
_useCache = useCache;
364373
_cache = useCache ? new Dictionary<GitConfigurationType, ConfigCache>() : null;
365374
}

0 commit comments

Comments
 (0)