Repository navigation
fix(git): share the worktree-list and unmerged-entry porcelain parsers with the SSH relay - #18389
Conversation
The relay carried its own copies of the worktree-list and unmerged-entry porcelain parsers, and both had drifted from the desktop originals: the relay copy had no `sparse` branch, so SSH sparse checkouts were never marked, and it never C-quote-decoded a conflict path, so a conflicted file with a space or non-ASCII byte was published under its raw quoted name and probed as missing. Move both parsers into src/shared and delete the relay copies, so there is one implementation each. Type the relay's worktree-list plumbing on GitWorktreeInfo instead of Record<string, unknown> so a field-copying step can no longer silently drop a newly parsed field. `isSparse` is a new optional field on the git.listWorktrees result (remote-wire-compatibility Rule 1); Git <2.28 omits the porcelain line and the field stays absent. No new git subcommand or option. Closes #18280
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (16)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe change moves Git status and worktree porcelain parsers into shared modules. Desktop and relay Git handlers now import the shared parsers. Relay worktree operations use the Merge Risk: ⚪ Minimal · up to This change consolidates desktop and relay Git porcelain parsing while retaining compatibility for older Git versions and remote clients. Current coverage indicates the shared parsing and relay behavior are aligned, with no remaining merge-readiness risk identified. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description provides detailed technical context, links issue Resolution Add the missing template sections and required information. Include an ELI5 summary, explicit What Changed and Why sections, Visual Proof with N/A and a reason if no visual proof applies, Testing checklist status and tested platforms, AI disclosure or the applicable internal-contributor exemption, Review, Agent skill upstream boundary, Notes, and the final checklist. Full details: Linked Issues checkExplanation The changes satisfy issue
✨ Finishing Touches 💡 1📝 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 |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- De-duplicate the worktree-list porcelain parser —
parseWorktreeListmoved fromsrc/main/git/worktree-list-parser.tstosrc/shared/git-worktree-porcelain-parser.ts; the relay'sgit-handler-utils.tscopy (which lacked thesparsebranch) is deleted. - De-duplicate the unmerged-entry parser —
parseUnmergedEntry/parseConflictKind/getConflictCompatibilityStatusmoved tosrc/shared/git-status-conflict-entries.ts; the relay copy (raw C-quoted paths, syncexistsSyncprobe) is gone, andgetStatusOpnowawaits the shared async parser. - Tighten relay worktree plumbing —
normalizeMainWorktreePath,normalizeRelayWorktrees, andannotatePrunableWorktreesByExistencenow operate onGitWorktreeInfoinstead ofRecord<string, unknown>. - Add relay↔desktop parity test —
git-porcelain-local-parity.test.tspushes one fixture throughgit.listWorktreesandgetStatusOpand requires equality with the shared parsers across the-z, Git <2.36 fallback, and 2.25 baseline lanes.
This is a clean consolidation with a real bug fix. The wire additions (isSparse on git.listWorktrees, decoded conflict paths) are handled correctly — isSparse is a new optional field (Rule 1) and the conflict-path decode aligns the relay with the local path and the relay's own non-conflict entries, which already decoded. The async transition in getStatusOp is sound: parseUnmergedEntry cannot throw (its fs probe is caught internally), and the call site sits inside the existing try/abort handling. I ran the four touched test files (git-porcelain-local-parity, git-handler-worktree-list, git-handler-utils, worktree-porcelain-parsing): 25 tests pass.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…8389) The relay carried its own copies of the worktree-list and unmerged-entry porcelain parsers, and both had drifted from the desktop originals: the relay copy had no `sparse` branch, so SSH sparse checkouts were never marked, and it never C-quote-decoded a conflict path, so a conflicted file with a space or non-ASCII byte was published under its raw quoted name and probed as missing. Move both parsers into src/shared and delete the relay copies, so there is one implementation each. Type the relay's worktree-list plumbing on GitWorktreeInfo instead of Record<string, unknown> so a field-copying step can no longer silently drop a newly parsed field. `isSparse` is a new optional field on the git.listWorktrees result (remote-wire-compatibility Rule 1); Git <2.28 omits the porcelain line and the field stays absent. No new git subcommand or option. Closes stablyai#18280

Closes #18280.
The drift
src/relay/git-handler-utils.tscarried its own copies of two porcelain parsers that already existed on the desktop side, and both had drifted:worktree list --porcelainsparselineisSparse: truesparsebranch — SSH sparse checkouts were never markedu) record pathdecodeGitCQuotedPath(...)"a b.ts"was published under its quoted nameaccess+ onlyENOENT/ENOTDIRreads asdeletedexistsSync+catch → 'modified'Consequence on SSH only: sparse worktrees went unmarked in space analysis, the sparse UI, and the adoption guard; and a conflicted path containing a space or a non-ASCII byte was both mislabelled and probed at the wrong location, so it resolved to
deletedeven when the file was right there.The relay was already inconsistent with itself here — its ordinary status entries come from the shared
StatusPorcelainParser, which does decode C-quoted paths. Only the conflict rows did not.The fix
Delete the carrier rather than patch each copy:
src/main/git/worktree-list-parser.ts→src/shared/git-worktree-porcelain-parser.tssrc/main/git/source-control/status-conflict-entries.ts→src/shared/git-status-conflict-entries.tsrg "function parseWorktreeList" srcandrg "function parseUnmergedEntry" srceach return exactly one hit.Additionally, the relay's worktree-list plumbing (
normalizeMainWorktreePath,annotatePrunableWorktreesByExistence,normalizeRelayWorktrees) moves fromRecord<string, unknown>toGitWorktreeInfo. That is the part that makes re-drift hard rather than merely fixed: a field-copying step can no longer silently drop a newly parsed field, and the compiler caught two loose test fixtures the moment the type tightened.Wire compatibility
git.listWorktreesnow includesisSparsewhen the host's Git emits the porcelain line — a new optional JSON field on an existing frame, Rule 1 ofdocs/reference/remote-wire-compatibility.md. No new opcode, no changed field meaning, no field stopped being populated. Old clients that never heard of it ignore it; old clients that do readisSparse(the sidebar badge, space analysis) simply start rendering SSH sparse worktrees correctly, which is the bug being fixed. No reader requires it.The conflict-path change does alter a published value on the SSH path: a C-quoted conflict path is now decoded. Flagging it explicitly rather than burying it — no client can be depending on the quoted form, because that is already what the local path and the relay's own non-conflict entries publish.
Git compatibility
The
sparseporcelain annotation is Git 2.28+. Older hosts simply omit the line andisSparsestays absent, which is correct — no version branch, no capability probe, and no new subcommand or option, so nothing to add todocs/reference/git-compatibility.md. Baseline 2.25 is covered by a directed test.Test
src/relay/git-porcelain-local-parity.test.tsis the point of the PR. It pushes one porcelain fixture through the relay's published call sites —git.listWorktreesover the real dispatcher, andgetStatusOp— and requires the answer to equal what the desktop's exported parsers produce, across the-zlane, the Git <2.36 fallback lane, and the 2.25 baseline.Failed-first: reintroducing a relay-local drifted copy (isSparse dropped, path left raw) fails 3 of the 5 parity tests. The other 2 are intended no-ops (
isSparseabsent on a 2.25 host; submodule conflicts dropped on both paths) and pass either way.Verification
pnpm tc— cleanpnpm test src— full treepnpm run check:code-quality:changed— 0 new findings across 16 changed files (max-linesproved live with a 400-line positive control first;git-handler-utils.tsdrops 166 lines, no bump anywhere)Nothing under
plans/is committed.