Skip to content

fix(worktree): don't flag a disabled sparse checkout as sparse - #9922

Merged
nwparker merged 1 commit into
stablyai:mainfrom
tao-io:fix/sparse-checkout-false-positive-after-disable
Jul 24, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
tao-io:fix/sparse-checkout-false-positive-after-disable

Conversation

@artile

@artile artile commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes a worktree falsely showing the sparse badge (and the "Files outside these paths are not on disk" tooltip) after git sparse-checkout disable had already restored every file to disk.

ELI5

If you turned on a "only show some files" mode and then turned it back off, the app kept warning that files were missing — even though they were all right there. Now it checks the real setting and shows the correct state.

Root cause & fix

detectSparseCheckout() inferred sparsity purely from the presence and non-zero size of <gitdir>/info/sparse-checkout. But git sparse-checkout disable sets core.sparseCheckout=false and repopulates the tree while deliberately leaving that pattern file in place, so the fast-path probe reported a false positive. The fix keeps the cheap fs.stat gate, but when the pattern file exists it confirms the effective core.sparseCheckout flag by reading git's config files directly (shared config plus per-worktree config.worktree, honoring worktree-override precedence) — no subprocess, and config parsing is extracted into the pure, exported parseCoreSparseCheckoutFlag().

Evidence

Validated & rebased onto latest main during a bug-bash triage on 2026-07-23.

  • Clean rebase onto origin/main (base 8a23618310, head 1582cc6abc).
  • Files: src/main/git/worktree.ts (fix), src/main/git/worktree-sparse-checkout.test.ts (test).
  • On branch: 11 tests passed (1 file). Reverting the fix (git checkout origin/main -- src/main/git/worktree.ts) with the test kept: 10 failed | 1 passed, including the behavioral guard "does not report isSparse after disable leaves the pattern file behind" and the parseCoreSparseCheckoutFlag suite (not exported on main).
  • npx oxlint src/main/git/worktree.ts clean (rc=0).
npx vitest run --config config/vitest.config.ts src/main/git/worktree-sparse-checkout.test.ts
# on branch:      Test Files 1 passed, Tests 11 passed
# fix reverted:   Test Files 1 failed, Tests 10 failed | 1 passed

Trade-offs

None — pure fix. The extra config read runs only for the rare worktree that still has a non-empty pattern file, and adds no subprocess.

Regression risk

Zero-regression: only the false-positive branch changes. Worktrees with no pattern file still short-circuit on the fs.stat fast path (byte-identical behavior), and genuinely sparse worktrees still report isSparse via the real core.sparseCheckout flag — both proven by the passing suite. Note (out of scope, per #9921): SSH/disconnected worktrees synthesize isSparse from persisted WorktreeMeta and are not reconciled here — a separate follow-up.

Original fix by @artile (Taras Kornichuk). Validated, rebased, and (where applicable) hardened via automated bug-bash review; original fix design preserved.

`git sparse-checkout disable` restores the full working tree and sets
core.sparseCheckout=false, but deliberately leaves <gitdir>/info/sparse-checkout
in place so the checkout can be re-enabled with the same patterns.
detectSparseCheckout treated the mere presence of that pattern file as "sparse",
so a fully-populated worktree kept showing the sparse badge and the misleading
"Partial checkout. Files outside these paths are not on disk." tooltip.

Gate the fast-path fs.stat behind a config read that confirms core.sparseCheckout
is actually enabled (shared repo config or per-worktree config.worktree, honoring
git's precedence). The config read runs only when a non-empty pattern file
exists, so it does not reintroduce the per-poll subprocess fan-out PR stablyai#1290
removed, and it reads git's config files directly (no subprocess).

Adds a real-git regression test (enable -> disable leaves file -> not sparse) and
unit tests for the git-config boolean parser.
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Sparse-checkout detection now uses the sparse pattern file as a gate and confirms core.sparseCheckout through shared and worktree-local Git configuration. A parser for Git boolean values, sections, comments, and precedence was added and exported. Tests cover enabled and disabled sparse-checkout states, leftover pattern files, configuration scoping, repeated assignments, valueless flags, and inline comments.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description covers the change well, but it omits required template sections like Screenshots, checklist items, AI Review Report, Security Audit, and Notes. Add the missing template sections, including Screenshots/No visual change, the testing checklist, AI Review Report with cross-platform checks, Security Audit, and Notes.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The change addresses #9921 by checking core.sparseCheckout, honoring config precedence, keeping the fast path, and adding regression and parser tests.
Out of Scope Changes check ✅ Passed The PR stays focused on sparse-checkout detection and its tests, with no clear unrelated code changes.
Title check ✅ Passed The title accurately summarizes the main fix: preventing disabled sparse checkouts from being reported as sparse.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/git/worktree-sparse-checkout.test.ts (1)

77-116: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Solid parser unit-test coverage, but no integration test covers config.worktree / commondir precedence.

These tests thoroughly lock down parseCoreSparseCheckoutFlag's text-parsing semantics, but nothing here exercises isSparseCheckoutEnabled/resolveGitCommonDir end-to-end (e.g., via git worktree add plus git config --worktree core.sparseCheckout ... in a linked worktree). That's the part of this PR most likely to have file-resolution bugs (see the extensions.worktreeConfig gap flagged in worktree.ts), and it's currently only indirectly covered.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1c3d4e56-186e-4370-94b0-0cd5b31931a3

📥 Commits

Reviewing files that changed from the base of the PR and between 39b124c and 1582cc6.

📒 Files selected for processing (2)
  • src/main/git/worktree-sparse-checkout.test.ts
  • src/main/git/worktree.ts

Comment thread src/main/git/worktree.ts
Comment on lines +1434 to +1442
// Whether core.sparseCheckout is actually enabled for this worktree. The value can live in the
// shared repo config or, when extensions.worktreeConfig is on, in the worktree-local
// `config.worktree`; later files override earlier ones, matching git's config precedence.
async function isSparseCheckoutEnabled(gitDir: string): Promise<boolean> {
const commonDir = await resolveGitCommonDir(gitDir)
const sharedFlag = await readCoreSparseCheckoutFlag(join(commonDir, 'config'))
const worktreeFlag = await readCoreSparseCheckoutFlag(join(gitDir, 'config.worktree'))
return worktreeFlag ?? sharedFlag ?? false
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the target function and related helpers.
FILE="src/main/git/worktree.ts"

echo "== outline =="
ast-grep outline "$FILE" --view expanded || true

echo
echo "== relevant lines around isSparseCheckoutEnabled =="
sed -n '1390,1475p' "$FILE"

echo
echo "== search for helper definitions/usages =="
rg -n "readCoreSparseCheckoutFlag|parseConfigBooleanFlag|extensions.worktreeConfig|config.worktree|isSparseCheckoutEnabled" "$FILE"

Repository: stablyai/orca

Length of output: 9027


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== search repo for worktreeConfig / config.worktree / sparseCheckout parsing =="
rg -n "extensions\.worktreeConfig|config\.worktree|sparseCheckout|core\.sparseCheckout" src/main/git src -g '!**/dist/**' -g '!**/build/**'

Repository: stablyai/orca

Length of output: 9067


🌐 Web query:

git config extensions.worktreeConfig config.worktree read only when enabled docs

💡 Result:

The extensions.worktreeConfig setting in Git does not make the config.worktree file read-only; rather, it enables a mode where configuration can be set specifically for individual worktrees [1][2]. When extensions.worktreeConfig is enabled, Git allows you to maintain worktree-specific settings in a file located at $GIT_DIR/config.worktree [3][1]. You can add or update configuration in this file using the command git config --worktree [1][2]. Key points regarding this extension: 1. Enabling it: You enable the extension using git config extensions.worktreeConfig true [1][2]. 2. Function: It allows worktrees to load settings from their specific config.worktree file in addition to the common repository config [3][4]. Settings in config.worktree override those in other configuration files [3][4]. 3. Migration: When enabling this, you must manually move certain configuration values (such as core.worktree and core.bare=true) from the common config file to the main worktree's config.worktree file, as they are no longer handled as special cases in the common config [3][1]. 4. Compatibility: Repositories with this extension enabled may not be accessible by older versions of Git [1][2]. There is no documentation indicating that enabling this extension imposes a read-only restriction on the config.worktree file; instead, it provides a mechanism to manage worktree-specific configurations [3][1].

Citations:


Gate config.worktree behind extensions.worktreeConfig isSparseCheckoutEnabled() always reads config.worktree, so a stale worktree-local flag can override .git/config even when Git would ignore that file. Only consult it when extensions.worktreeConfig is set.

@nwparker
nwparker merged commit e3cc08f into stablyai:main Jul 24, 2026
1 check passed
@nwparker

Copy link
Copy Markdown
Contributor

Thanks so much for this, @artile — don't flag a disabled sparse checkout as sparse. Verified (fail-on-main/pass-on-branch), rebased on latest main, reviewed, and merged. Really appreciate it! 🙏

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…yai#9922)

`git sparse-checkout disable` restores the full working tree and sets
core.sparseCheckout=false, but deliberately leaves <gitdir>/info/sparse-checkout
in place so the checkout can be re-enabled with the same patterns.
detectSparseCheckout treated the mere presence of that pattern file as "sparse",
so a fully-populated worktree kept showing the sparse badge and the misleading
"Partial checkout. Files outside these paths are not on disk." tooltip.

Gate the fast-path fs.stat behind a config read that confirms core.sparseCheckout
is actually enabled (shared repo config or per-worktree config.worktree, honoring
git's precedence). The config read runs only when a non-empty pattern file
exists, so it does not reintroduce the per-poll subprocess fan-out PR stablyai#1290
removed, and it reads git's config files directly (no subprocess).

Adds a real-git regression test (enable -> disable leaves file -> not sparse) and
unit tests for the git-config boolean parser.
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