Repository navigation
fix(git): read core.sparseCheckout the way git does - #10537
Conversation
Sparse-checkout detection parsed git config line-by-line and only accepted a section header alone on its line, so git's legal same-line form `[core] sparseCheckout = true` matched neither branch and was silently skipped: a genuinely sparse worktree lost its badge and partial-checkout warning. It also read `config.worktree` unconditionally, although git honors that file only while extensions.worktreeConfig is on, so a stale worktree config could override the repo's real setting. Headers are now consumed left-to-right off each line (further headers and one assignment may follow), and config.worktree is read only behind the extension gate. Every new expectation was confirmed against real `git config --get`.
📝 WalkthroughWalkthroughSparse-checkout detection now parses shared Git configuration text and consults 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
… value Git does not reject `[core] sparseCheckout = true bogus = false` outright: it parses the line and takes the whole tail as one value (`git config --list` reports `core.sparsecheckout=true bogus = false`), then fails only the boolean coercion. The expectation is unchanged; the comment now matches the binary.
CodeRabbit review dispositionRecording a decision for every item CodeRabbit raised on this PR. 1. Inline code comments — none. CodeRabbit reported "No actionable comments were generated in the recent review" against 2. Pre-merge check: Description check 3. Pre-merge checks that passed — Title check, Docstring Coverage, Linked Issues, Out of Scope Changes. No action needed. 4. Finishing Touches ("Generate docstrings") — DECLINED. These are opt-in checkboxes, not findings. The changed functions already carry why-focused comments, and Independent review notesReviewed with two adversarial subagents (parser-fuzzing lens; extension-gate/integration lens). Because this is a hand-rolled config parser, every claim was checked against the real git binary rather than against the spec.
One fix pushed ( |
Review round 2 — both adversarial subagents returned CLEANUpdating my earlier comment: at the time I posted it neither subagent had delivered its report. Both have now returned, both CLEAN, neither disputing the verdict. One net-new finding was worth acting on. New: this PR also removes a pre-existing FALSE POSITIVE — the opposite failure mode from the one in the title, and previously untested. A line shaped Git reports Supporting evidence from the fuzzing subagent (differential vs real git across ~5,100 generated configs): the new parser agrees with git on all 3,687 git-parseable cases; the pre-fix parser produced 8 false positives and 234 false negatives on the same corpora. Deferrals — endorsed, with a new argument in their favor. An Remaining known-and-bounded gaps, all byte-identical before and after this PR, all documented in the description: line continuations (trailing CI note: the one |
* fix(git): read core.sparseCheckout the way git does Sparse-checkout detection parsed git config line-by-line and only accepted a section header alone on its line, so git's legal same-line form `[core] sparseCheckout = true` matched neither branch and was silently skipped: a genuinely sparse worktree lost its badge and partial-checkout warning. It also read `config.worktree` unconditionally, although git honors that file only while extensions.worktreeConfig is on, so a stale worktree config could override the repo's real setting. Headers are now consumed left-to-right off each line (further headers and one assignment may follow), and config.worktree is read only behind the extension gate. Every new expectation was confirmed against real `git config --get`. * test(git): correct what git actually does with a trailing-junk config value Git does not reject `[core] sparseCheckout = true bogus = false` outright: it parses the line and takes the whole tail as one value (`git config --list` reports `core.sparsecheckout=true bogus = false`), then fails only the boolean coercion. The expectation is unchanged; the comment now matches the binary.
Summary
Sparse-checkout detection (
isSparseCheckoutEnabledinsrc/main/git/worktree.ts) reads git's config files directly — deliberately, to avoid the per-pollgit sparse-checkout listsubprocess fan-out that PR #1290 removed. Two bugs made it disagree with git:^...$. Git's config parser is character-based, not line-based, so a header may be followed by an assignment on the same line.[core] sparseCheckout = truematched neither the header branch nor the assignment branch — the line was silently skipped, the parser never entered[core], and detection returnedfalse. A genuinely sparse worktree lost itssparsebadge (WorktreeCard.tsx,WorkspaceSpaceManagerPanel.tsx) and its partial-checkout warning.config.worktreewas read unconditionally. The function's own comment said it applies "when extensions.worktreeConfig is on", but the extension was never checked. Git honors that file only whileextensions.worktreeConfig=true, so a staleconfig.worktreeleft behind by an earlier sparse checkout could override the repo's real setting.Fix
[core "sub"] [core] x = true-> the last one wins), but a value runs to end of line, so only one assignment can share a line.config.worktreeonextensions.worktreeConfigread from the shared repo config — exactly git's own rule, and not circular. Confirmed empirically that git honors this extension atcore.repositoryformatversion = 0, and thatgit sparse-checkoutwrites the extension to the shared config itself whenever it writesconfig.worktree, so the gate never hides a flag git would have read.Deliberate existing behaviors are preserved: only the last assignment wins,
[core "subsection"]is still not treated as[core], comment stripping and the valueless-boolean form (sparseCheckout=> true) are unchanged.The header fix also removes a pre-existing false positive, in the opposite direction from the bug in the title. A line shaped
[section "sub"]key = value(header plus assignment on one line) matched neither branch of the old anchored regex, so the parser never left[core]and credited the following indented line to it:Git reports
core.sparseCheckoutas unset here; the old parser returnedtrue, badging a non-sparse worktree as sparse. The new parser returns unset. Covered by a regression test that fails on the pre-fix parser.No subprocess, no new git invocation, no capability probing — the Git 2.25 baseline is unaffected, and SSH / WSL / folder-workspace paths are untouched (this reads files through the same fs calls as before). The gate also removes an fs read in the common case, since
config.worktreeis no longer opened when the extension is off.Screenshots
No visual change. The change restores an existing badge/warning; it does not alter their appearance.
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildsrc/main/git/worktree-sparse-checkout.test.ts, 21 pass. New: 8 parser cases (same-line assignment incl. no-space and valueless, section stays open for later lines, last-header-wins, subsection same-line, mixed-form last-assignment-wins, comment/whitespace variants, trailing junk, subsection-header-with-same-line-assignment) and 2 real-repo cases for the extension gate that assertgit config --get core.sparseCheckoutagrees with detection.Revert-check (source reverted with
git apply -R, tests kept): 8 failed | 13 passed. Restored: 21 passed. The two new tests that pass either way are intentional regression guards against the opposite failure mode ([core "sub"]still ignored;config.worktreehonored when the extension is on).Full
src/main/gitsuite: 39 files, 592 tests, all pass.AI Review Report
Reviewed with an AI agent plus two independent adversarial subagents (parser-fuzzing lens; extension-gate/integration lens). Both returned CLEAN; neither disputed the verdict.
Main risks checked and what was found:
git config --file --get --type=bool): BOM, CRLF,[CORE]/caps key, quoted"true", quoted value containing#, empty value, hyphenated key,[core "a]b"], unterminated quote,[[core]], and[alias]/core.editorvalues containing literal[core] sparseCheckout = truetext. The parser matches git on all of them, with zero false positives. A differential sweep over ~5,100 generated configs agreed with git on every git-parseable case, while the pre-fix parser produced 8 false positives and 234 false negatives on the same corpora. On inputs git treats asfatal, the parser conservatively yields not-sparse — and those are unreachable anyway, sincegit worktree list --porcelainitself dies on a bad config, so no worktree is ever produced to badge.git sparse-checkout setin a linked worktree writesextensions.worktreeConfig=trueto the shared config andcore.sparseCheckout=trueto that worktree'sconfig.worktree, atrepositoryformatversion=0. The new code badges the linked worktree sparse and the main worktree not-sparse, matching git. The gate can therefore never hide a flag git would have honored.parseCoreSparseCheckoutFlagis consumed only by its own test; the removedreadCoreSparseCheckoutFlaghad no other callers.path.join;split(/\r?\n/)handles CRLF andString.trim()strips a BOM, both verified. No shell invocation, no shortcut/label/accelerator surface, no Electron platform-specific behavior is touched. Verified at runtime on macOS only; the real-repo tests areskipIf(win32), consistent with the pre-existing tests in this file.GitCapabilityCacheentry is needed and the Git 2.25 baseline is untouched.Fixed as a result of review: (a) a test comment claimed git "rejects this line outright" for
[core] sparseCheckout = true bogus = false; the binary actually parses the line and takes the whole tail as one value (git config --listreportscore.sparsecheckout=true bogus = false), failing only the boolean coercion — comment corrected, expectation unchanged; (b) added the regression test for the false-positive class described above, which previously had no coverage.Security Audit
Low risk. No command execution, no IPC, no auth, no secrets, no dependency change. Input handling is the one relevant surface: the parser consumes local git config text, and the regexes were reviewed for catastrophic backtracking — both are linear with no nested unbounded quantifiers, and the header loop strictly shortens the remaining string each iteration, so it terminates. Path handling uses
joinon an already-resolved gitdir with fixed filenames (config,config.worktree), so there is no user-controlled path component. Read failures fall back to empty text rather than throwing, and every ambiguous or malformed input resolves to "not sparse", which is the non-destructive default.Notes
Knowingly not fixed — both are real gaps, both are out of scope for this one-concern PR, since implementing a git-config resolver by hand is a much larger change and a real regression risk:
[include] path = .../includeIfindirection is ignored, so a sparse flag reached through an include is missed. Note this cuts both ways: an[include]-providedextensions.worktreeConfigresolves totrueundergit config --get, yet git still does not honorconfig.worktree, becauseread_repository_formatdoes not process includes. The direct-file read used here matches git's real behavior; agit config --get-based implementation would not.core.sparseCheckoutacross system -> global -> repo -> worktree; this reads repo config +config.worktreeonly. A--global core.sparseCheckoutwould be missed. In practicegit sparse-checkoutalways writes repo-scoped, so this is an edge case.Also pre-existing and deliberately untouched: line continuations (a trailing
\) are not followed, and a couple of exotic value forms (sparseCheckout = 2,sparseCheckout = tr"ue") read as false where git reads true. All are byte-identical before and after this PR, and all are bounded by the fact that the parser is only reached when<gitdir>/info/sparse-checkoutexists and is non-empty.Asking git itself instead was considered and rejected:
detectSparseCheckoutruns on the list path, andlistWorktreesStrictdeliberately does not thread itsGitWorktreeExecOptionsintoannotateSparseCheckoutStatus, so a subprocess could not be routed to the right host (WSL distro / SSH provider / relay). Threading exec options through the whole list path plus a per-hostGitCapabilityCacheentry is a different, larger PR. A narrower "just read the global config file too" shortcut is worse than the gap it closes, because on SSH/WSL it would resolve the wrong host's home directory.