Skip to content

fix(git): share the worktree-list and unmerged-entry porcelain parsers with the SSH relay - #18389

Merged
nwparker merged 1 commit into
mainfrom
fix/shared-git-porcelain-parsers
Sep 3, 2026
Merged

nwparker merged 1 commit into
mainfrom
fix/shared-git-porcelain-parsers

Conversation

@nwparker

@nwparker nwparker commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​260 $\color{#cf222e}{\Huge{\mathbf{−}}}$​82 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​178
Prod 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​30 $\color{#cf222e}{\Huge{\mathbf{−}}}$​196 $\color{#cf222e}{\Huge{\mathbf{−}}}$​166

Closes #18280.

The drift

src/relay/git-handler-utils.ts carried its own copies of two porcelain parsers that already existed on the desktop side, and both had drifted:

desktop relay (before)
worktree list --porcelain sparse line isSparse: true no sparse branch — SSH sparse checkouts were never marked
unmerged (u) record path decodeGitCQuotedPath(...) raw — a conflicted "a b.ts" was published under its quoted name
missing-file probe access + only ENOENT/ENOTDIR reads as deleted existsSync + 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 deleted even 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.ts
  • src/main/git/source-control/status-conflict-entries.ts → src/shared/git-status-conflict-entries.ts
  • relay copies removed; all desktop call sites and all relay call sites now import the one implementation.

rg "function parseWorktreeList" src and rg "function parseUnmergedEntry" src each return exactly one hit.

Additionally, the relay's worktree-list plumbing (normalizeMainWorktreePath, annotatePrunableWorktreesByExistence, normalizeRelayWorktrees) moves from Record<string, unknown> to GitWorktreeInfo. 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.listWorktrees now includes isSparse when the host's Git emits the porcelain line — a new optional JSON field on an existing frame, Rule 1 of docs/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 read isSparse (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 sparse porcelain annotation is Git 2.28+. Older hosts simply omit the line and isSparse stays absent, which is correct — no version branch, no capability probe, and no new subcommand or option, so nothing to add to docs/reference/git-compatibility.md. Baseline 2.25 is covered by a directed test.

Test

src/relay/git-porcelain-local-parity.test.ts is the point of the PR. It pushes one porcelain fixture through the relay's published call sites — git.listWorktrees over the real dispatcher, and getStatusOp — and requires the answer to equal what the desktop's exported parsers produce, across the -z lane, 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 (isSparse absent on a 2.25 host; submodule conflicts dropped on both paths) and pass either way.

Verification

  • pnpm tc — clean
  • pnpm test src — full tree
  • pnpm run check:code-quality:changed — 0 new findings across 16 changed files (max-lines proved live with a 400-line positive control first; git-handler-utils.ts drops 166 lines, no bump anywhere)
  • Docker SSH lane

Nothing under plans/ is committed.

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
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 9f9c3938-3c6c-4a53-baa1-64b1eb81f9f5

📥 Commits

Reviewing files that changed from the base of the PR and between d05dd8e and 383380a.

📒 Files selected for processing (16)
  • src/main/git/source-control/status-read.ts
  • src/main/git/worktree-base-refresh-analysis.ts
  • src/main/git/worktree-base-refresh.ts
  • src/main/git/worktree-branch-removal.ts
  • src/main/git/worktree-list-reader.ts
  • src/main/git/worktree.ts
  • src/relay/git-handler-branch-cleanup.ts
  • src/relay/git-handler-status-ops.ts
  • src/relay/git-handler-utils.test.ts
  • src/relay/git-handler-utils.ts
  • src/relay/git-handler-worktree-list.test.ts
  • src/relay/git-handler-worktree-list.ts
  • src/relay/git-handler-worktree-operations.ts
  • src/relay/git-porcelain-local-parity.test.ts
  • src/shared/git-status-conflict-entries.ts
  • src/shared/git-worktree-porcelain-parser.ts
💤 Files with no reviewable changes (1)
  • src/relay/git-handler-utils.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The 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 GitWorktreeInfo type. Removed parser helpers and related tests from git-handler-utils. Added parity tests for worktree delimiters, Git version fallback, conflict paths, and submodule conflicts.

Merge Risk: ⚪ Minimal · up to 38338

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides detailed technical context, links issue #18280, explains compatibility, and lists verification. However, it omits most required template sections, including ELI5, explicit Wha… 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 di…
Docstring Coverage ⚠️ Warning Docstring coverage is 13.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 15 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: sharing the worktree-list and unmerged-entry parsers with the SSH relay.
Linked Issues check ✅ Passed The changes satisfy issue #18280: they centralize the worktree-list and unmerged-entry parsers, remove relay copies, preserve optional isSparse behavior, use shared GitWorktreeInfo typing, and add rel…
Out of Scope Changes check ✅ Passed The changed production files and tests support the parser-sharing objective, compatibility behavior, relay typing, or verification. No unrelated functional changes are evident.
Full details: Description check

Explanation

The description provides detailed technical context, links issue #18280, explains compatibility, and lists verification. However, it omits most required template sections, including ELI5, explicit What Changed and Why headings, Visual Proof or N/A, checklist items, Review, Agent skill upstream boundary, Notes, and AI disclosure or its exemption.

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 check

Explanation

The changes satisfy issue #18280: they centralize the worktree-list and unmerged-entry parsers, remove relay copies, preserve optional isSparse behavior, use shared GitWorktreeInfo typing, and add relay/local parity tests. No new Git commands or plans files were added.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • De-duplicate the worktree-list porcelain parser — parseWorktreeList moved from src/main/git/worktree-list-parser.ts to src/shared/git-worktree-porcelain-parser.ts; the relay's git-handler-utils.ts copy (which lacked the sparse branch) is deleted.
  • De-duplicate the unmerged-entry parser — parseUnmergedEntry/parseConflictKind/getConflictCompatibilityStatus moved to src/shared/git-status-conflict-entries.ts; the relay copy (raw C-quoted paths, sync existsSync probe) is gone, and getStatusOp now awaits the shared async parser.
  • Tighten relay worktree plumbing — normalizeMainWorktreePath, normalizeRelayWorktrees, and annotatePrunableWorktreesByExistence now operate on GitWorktreeInfo instead of Record<string, unknown>.
  • Add relay↔desktop parity test — git-porcelain-local-parity.test.ts pushes one fixture through git.listWorktrees and getStatusOp and 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.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 860ee73 into main Sep 3, 2026
33 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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
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.

Share git porcelain parsers so SSH cannot drift from local

1 participant