Skip to content

Workaround libgit2 safe.directory case mismatch bug#1899

Merged
tyrielv merged 2 commits intomicrosoft:masterfrom
tyrielv:tyrielv/safedirectory-caseinsensitive
Mar 9, 2026
Merged

Workaround libgit2 safe.directory case mismatch bug#1899
tyrielv merged 2 commits intomicrosoft:masterfrom
tyrielv:tyrielv/safedirectory-caseinsensitive

Conversation

@tyrielv
Copy link
Contributor

@tyrielv tyrielv commented Jan 30, 2026

Libgit2 has a bug where it is case sensitive for safe.directory (especially the drive letter) when git.exe isn't. Until a fix can be made and propagated, work around it by matching the repo path requested to the configured safe directory.

See libgit2/libgit2#7037

@tyrielv tyrielv force-pushed the tyrielv/safedirectory-caseinsensitive branch from 9f64938 to ba58df0 Compare January 30, 2026 17:41
@tyrielv tyrielv marked this pull request as draft January 30, 2026 18:01
@tyrielv tyrielv force-pushed the tyrielv/safedirectory-caseinsensitive branch from 61345a8 to a5e262e Compare January 30, 2026 18:30
@tyrielv tyrielv marked this pull request as ready for review February 11, 2026 19:35
Replace the heavyweight SafeDirectoryOwnershipTests functional test
(which required elevation, P/Invoke for SeRestorePrivilege, directory
ownership changes, and global git config manipulation) with two layers
of lightweight unit tests:

Layer 1: NormalizePathForSafeDirectoryComparison - pure string tests
covering backslash/forward-slash conversion, case normalization,
trailing slash trimming, and null/empty safety.

Layer 2: Constructor control-flow tests using a mock subclass that
overrides the native calls (InitNative, TryOpenRepo, GetLastNativeError,
GetSafeDirectoryConfigEntries) to verify the safe.directory case-
sensitivity workaround logic without touching libgit2 or real config.

To support testability, extract virtual methods from LibGit2Repo for
native interactions and make CheckSafeDirectoryConfigForCaseSensitivity-
Issue protected. The NormalizePath helper is renamed to
NormalizePathForSafeDirectoryComparison and scoped as internal.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tyrielv tyrielv merged commit 4b3bc38 into microsoft:master Mar 9, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants