Repository navigation
Conversation
On Windows, Git canonicalizes both the repository path and each `safe.directory` allowlist entry to their real on-disk form before comparing them, so the comparison is effectively case-insensitive over the whole path, including the drive letter. libgit2 compared the paths with a case-sensitive `strcmp`, so an entry like `c:/repo` did not match a repository recorded as `C:/repo` (or `C:/Repo`), and the repository failed to open with a spurious ownership error. Compare the configured entry against the repository path case-insensitively on Windows, matching Git. POSIX filesystems are case-sensitive, so the comparison is unchanged there. Add Windows-only tests that open a repository allowlisted with the opposite drive-letter case, and with the entire path in a different case. Assisted-by: Claude Opus 4.8 Signed-off-by: Tyrie Vella <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7037
Problem
On Windows, opening a repository whose ownership check relies on a
safe.directoryallowlist entry fails withGIT_EOWNERwhen the entry differs in case from the repository path -- in practice, the drive letter (c:vsC:).git.exeaccepts the same entry.Root cause
validate_ownership_cbcompares the configuredsafe.directoryentry against the repository path with a case-sensitivestrcmp/prefix compare.Git does not have a case rule here at all:
ensure_valid_ownership(setup.c) canonicalizes both the repository path and each entry to their real on-disk form viareal_pathdup(which, on Windows, resolves throughGetFinalPathNameByHandleand so normalizes drive-letter case), then compares.safe.directoryis read from protected (system/global) config only, so the repo'score.ignorecasenever enters the decision -- the match comes from canonicalization, not case-folding.libgit2 already resolves the repository path with
git_fs_path_prettify(p_realpath), but on Windows that usesGetLongPathName, which corrects path-component case but not the drive letter -- and the entry is not canonicalized at all. Hence the drive-letter-only mismatch.Fix
Compare the configured entry against the repository path case-insensitively on Windows; POSIX filesystems stay case-sensitive. This is a lightweight approximation of git's
real_pathdupcanonicalization -- it resolves the reported drive-letter symptom (and tolerates component-case variants, as git does), without re-implementing full real-path resolution of the entry.Known divergence (low risk): on a case-sensitive Windows volume/dir, git would compare canonicalized paths case-sensitively, whereas this compare always folds case. It can only ever make an explicitly allowlisted path match a case variant of itself.
Tests
Adds two Windows-only tests in
repo::open:The full test suite passes.