Repository navigation
Reject sparse-directory index entries in the projection parser - #2191
Merged
Tyrie Vella (tyrielv) merged 2 commits intoNov 16, 2026
Merged
Tyrie Vella (tyrielv) merged 2 commits into
Tyrie Vella (tyrielv) merged 2 commits into
Conversation
Tyrie Vella (tyrielv)
force-pushed
the
tyrielv/sparse-index/projection-reject-sparse-dirs
branch
from
November 14, 2026 00:23
4c52905 to
d1ea3a9
Compare
Git can write a sparse index (index.sparse). A sparse index stores a collapsed subtree as one entry with mode 040000 and a path that ends in '/'. The projection cannot use such an entry. The parser checks the mode field only when SupportsFileMode is true, and it is false on Windows. So the parser accepted the entry as a file. The mount then reported that the repository was ready, and ProjFS enumeration failed about 2.7 seconds later with "fileName cannot be empty". The projection also omitted every file in the collapsed subtree. Recognise mode 040000 as FileType.Directory. GitIndexParser.ParseIndex now rejects a sparse-directory entry before any entry callback receives it. The check uses the trailing '/', so it works when the parser skips the mode field. Every index parse is covered: the projection build (from .git\index or from the persisted GVFS_projection copy), the placeholder scan, index validation, and the folder count for 'gvfs health'. The new SparseIndexNotSupportedException names the entry and gives recovery steps that work with released versions of Git: turn off index.sparse in the repository config, expand the index, delete the persisted projection index, and mount. Control characters in the entry path are escaped in the message. The mount reports only this message. The mount log keeps the stack trace. When the placeholder scan finds a sparse index, the projection is marked invalid, so that the next mount reports the message. 'gvfs repair' reports the message and does not replace the index with one built from HEAD, because that would discard staged changes. Assisted-by: Claude Opus 5.5 Signed-off-by: Tyrie Vella <[email protected]>
Tyrie Vella (tyrielv)
force-pushed
the
tyrielv/sparse-index/projection-reject-sparse-dirs
branch
from
November 16, 2026 18:31
d1ea3a9 to
5fd6d82
Compare
Tyrie Vella (tyrielv)
marked this pull request as ready for review
November 16, 2026 21:58
Tyrie Vella (tyrielv)
enabled auto-merge
November 16, 2026 21:58
|
[KeithBot]: Approach: Right layer: one guard in GitIndexParser.ParseIndex covers every index reader (projection, GVFS_projection copy, placeholder scan, health, repair) before any consumer sees an entry. Validation
🤖 KeithBot · claude-opus-5.5, gpt-6.1-sol, gemini-4-argon + approach review · reply on a thread to dispute |
Recovery step 2 runs 'git config --worktree index.sparse false'. Git rejects --worktree when the repository has more than one worktree (including a prunable one) and extensions.worktreeConfig is off. A primary enlistment turns that extension on only when a linked worktree has a config.worktree file, so the step can fail with "--worktree cannot be used with multiple working trees". Tell the user to run 'git config index.sparse false' in that case. Git reads no config.worktree file while the extension is off, so the repository config is the right place. The step keeps --worktree first, because with the extension on, a value in config.worktree would hide a value in the repository config. Assisted-by: Claude Opus 5.5 Signed-off-by: Tyrie Vella <[email protected]>
|
[KeithBot]: ✅ Resolved · iteration 2 (
Validation
Approving. 🤖 KeithBot · recheck by claude-opus-5.5 · reply on a thread to dispute |
Keith Klein (KeithIsSleeping)
approved these changes
Nov 16, 2026
This was referenced Nov 17, 2026
Merged
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.
Problem and Context
Git can write a sparse index (
index.sparse=true). In a sparse index, one entry stands for a whole subtree. This sparse-directory entry has mode040000, a tree ID, the skip-worktree bit, and a path that ends in/. VFS for Git builds its projection from the index, and the projection parser does not know this entry type.The parser does not reject the entry. A reviewer can think that it does, because
GitIndexParserhas a switch that rejects unknown file types. But the parser reads the mode field only whenSupportsFileModeis true, and it is false on Windows. So the parser accepts a040000entry as a file:/.ArgumentException: fileName cannot be empty, and the mount process stops. The error does not identify the cause.Other index parses have the same problem. The placeholder scan treats every placeholder under a collapsed folder as absent from the index, so it adds each one to ModifiedPaths and removes it from the placeholder list.
gvfs healthcounts the collapsed folder as one folder.The persisted projection index (
.gvfs\GVFS_projection) is a copy of the index from the last projection build. If git collapsed the index while the repository was mounted, this copy is also sparse. When the projection is valid, the mount parses this copy and not.git\index.This change does not add sparse index support. It makes the parser identify the entry, stop before any consumer uses it, and tell the user how to expand the index. This change targets
master, so that released versions reject a sparse index with a clear message. Sparse index support will be added tovnext, notmaster.Changes
FileType.Directory, and makeFileTypeAndModerecognise mode040000. When the platform parses modes, the parser requires zero permission bits for a directory entry.GitIndexEntry.PathEndsInSlash. The guard uses the trailing/, because Windows does not parse the mode field. The guard also rejects an entry withFileType.Directory.GitIndexParser.ParseIndexcalls the newFailIfSparseDirectoryEntryfor each entry, after it reads the path and before the entry callback. So the guard covers every parse: the projection build from.git\indexor from the persisted projection index, the placeholder scan,ValidateIndex, andCountIndexFolders.FailIfSparseDirectoryEntrythrows the newSparseIndexNotSupportedException. It derives fromException, notIOException, because the index parsing thread retries anIOException, and a retry cannot succeed for a sparse index.gvfs mount:--worktreewrites to the worktree config whenextensions.worktreeConfigis on, and to the repository config when it is off. Git rejects--worktreewhen the extension is off and the repository has another worktree, so the step gives the plaingit configcommand for that case. Git reads no worktree config while the extension is off.git sparse-checkout disabledoes not work here: with hooks on, the pre-command hook stops it, and with hooks off, it fails because it writes to the unmounted working directory.\uXXXX. A crafted path cannot add lines, steps, or terminal escape sequences to the message.InProcessMountreportsSparseIndexNotSupportedExceptionwith its message only. Other exceptions fromTryStartstill include the stack trace.GitIndexProjection.BuildProjectionalready writes the full exception to the mount log.BuildProjectionmarks the projection invalid. This is existing behaviour, so the next mount copies.git\indexagain.GitIndexProjection.AddMissingModifiedFilesnow catchesSparseIndexNotSupportedException, marks the projection invalid, and returnsFatalError. The background task runner then stops the mount, and the next mount parses.git\indexand shows the message.RepairJob.TryParseIndexreportsSparseIndexNotSupportedExceptionasCantFixwith the message. Before this change, any parse failure wasFixable, andgvfs repair --confirmreplaced the index with one built from HEAD. That discards staged changes, and a sparse index is valid.MockPlatformFileSystem.SupportsFileModesettable, so that unit tests can parse with and without the mode field.EnlistmentHydrationSummaryTeststo a shared test helper,GitIndexV4Writer, and give it the entry mode and object ID.EnlistmentHydrationSummaryTestsand the new tests use it.SparseIndexParsingTests:FileTypeAndModerecognises mode040000.ValidateIndexrejects a sparse-directory entry with and without mode parsing, and that the message contains each recovery step.040000entry without a trailing/, and a040000entry with permission bits.CountIndexFoldersrejects a sparse index..git\indexand a sparse persisted projection index, and callsGitIndexProjection.Initialize. The test checks thatInitializethrows, that the projection is marked invalid, and that.git\indexdoes not change.AddMissingModifiedFiles. The test checks that the result isFatalErrorand that the projection is marked invalid.GitIndexRepairJob.HasIssuereturnsCantFixfor a sparse index, with the recovery steps.SparseIndexMountTests. The test unmounts, setsindex.sparse=truein the repository config, collapses every top-level folder, and copies the sparse index to the persisted projection index. The test checks thatgvfs mountfails with the message and without a stack trace. The test then runs the two commands and deletes the file that the message names, and mounts. The test checks thatindex.sparseisfalse, thatgit ls-files -smatches the output from before the collapse, and that a file in a collapsed folder is projected.Known gaps and deliberate decisions
ParseIndexThreadMainwith a sparse index. It calls the sameBuildProjectionthat theInitializetest covers, and its outer catch stops the process. No follow-up planned.SetProjectionInvalidwrites the repository metadata throughFileBasedCollection, which retries a failed write without a limit. A persistent write failure on the new rejection path can delay the mount exit. The same hazard applies to every metadata write today. No follow-up planned in this change.