Description
Defensive maintenance finding from an internal audit of 074a2366bf. No exploit steps or payloads. Implement by following this plan exactly. Do not commit files under plans/ in the implementation PR.
Plan 013: Share git porcelain parsers so SSH cannot drift from local
Executor instructions: Follow this plan step by step. Run every
verification command and confirm the expected result before moving to the
next step. If anything in the "STOP conditions" section occurs, stop and
report — do not improvise. When done, update the status row for this plan
inplans/README.md— unless a reviewer dispatched you and told you they
maintain the index.Drift check (run first):
git diff --stat 074a2366bf..HEAD -- src/main/git/worktree-list-parser.ts src/relay/git-handler-utils.ts src/main/git/source-control/status-conflict-entries.ts src/relay/git-handler-worktree-operations.ts src/relay/git-handler-status-ops.ts
If any in-scope file changed since this plan was written, compare the
"Current state" excerpts against the live code before proceeding; on a
mismatch, treat it as a STOP condition.
Status
- Priority: P1
- Effort: M
- Risk: MED
- Depends on: none
- Category: tech-debt
- Planned at: commit
074a2366bf, 2026-09-03
Why this matters
Desktop parseWorktreeList understands porcelain sparse → isSparse. The relay copy in git-handler-utils.ts has no sparse branch, so SSH sparse checkouts are unmarked (space-analysis, setup/sparse UI, adoption guards). Relay parseUnmergedEntry skips decodeGitCQuotedPath and uses existsSync with catch → 'modified', so quoted conflict paths and fs-probe errors diverge from local (status-conflict-entries.ts).
docs/reference/remote-wire-compatibility.md Rule 1: adding isSparse on listed worktrees is an optional field — safe. Do not add a new opcode.
Current state
Desktop src/main/git/worktree-list-parser.ts:38-59 handles line === 'sparse' and spreads isSparse.
Relay src/relay/git-handler-utils.ts:138-191 parseWorktreeList has worktree/HEAD/branch/bare/locked/prunable — no sparse.
Desktop src/main/git/source-control/status-conflict-entries.ts:10-20:
const filePath = decodeGitCQuotedPath(parts.slice(10).join(' '))Relay src/relay/git-handler-utils.ts:57-90:
const filePath = parts.slice(10).join(' ')
// ...
status = existsSync(path.join(worktreePath, filePath)) ? 'modified' : 'deleted'
} catch {
status = 'modified'
}Local unmerged parser treats only ENOENT/ENOTDIR as deleted (read the rest of status-conflict-entries.ts). Match that.
Git 2.25 baseline (docs/reference/git-compatibility.md): sparse in git worktree list porcelain is Git 2.28+. Older hosts simply omit the line — isSparse absent is correct. Do not require Git 2.28.
CONTRIBUTING: GitLab/other providers are irrelevant here (porcelain is git itself). Windows path joins on the relay OS.
Commands you will need
| Purpose | Command | Expected on success |
|---|---|---|
| Typecheck | pnpm tc:node |
exit 0 |
| Desktop parser tests | pnpm test src/main/git/worktree-list-porcelain.test.ts |
all pass (filename from glob if different) |
| Relay tests | pnpm test src/relay/git-handler-utils.ts src/relay/git-handler-status-ops.test.ts src/relay/git-handler-worktree-list.test.ts |
all pass |
| Lint changed | pnpm run check:code-quality:changed |
exit 0 |
Scope
In scope:
- Move or share
parseWorktreeList/ unmerged-entry path decode intosrc/shared/(electron-free) or have relay import the desktop parser if that import is already allowed. Prefersrc/sharedif relay must not importsrc/main/git. src/relay/git-handler-utils.ts— delete the drifted copiessrc/main/git/worktree-list-parser.ts— re-export from shared or become the shared modulesrc/main/git/source-control/status-conflict-entries.ts— share decode + missing-file probe- Tests on both sides
src/relay/git-handler-worktree-operations.tsonly if it must start forwardingisSparse
Out of scope:
- Filesystem sparse-checkout probe in
worktree-listing.ts(local extra stat) — optional to call from relay; do not block on it - Plan 007 remove listing
- New git subcommands
Git workflow
- Branch:
fix/shared-git-porcelain-parsers - Commit:
fix(git): parse sparse and cquoted paths on the SSH relay - Do NOT push or open a PR unless the operator instructed it.
Steps
Step 1: Shared worktree list parser
Put one parseWorktreeList in src/shared (or keep desktop file and import it from relay if src/relay already imports src/main/git — pty-handler.ts imports main, but prefer shared to avoid deepening that).
Must handle sparse like desktop. Keep prunable/locked/cquoted decode.
Wire src/relay/git-handler-worktree-operations.ts git.listWorktrees through it so isSparse is on the JSON result.
Verify: existing worktree-list-porcelain.test.ts (glob **/*worktree-list*porcelain*) still pass. Add a relay or shared test: a porcelain block with sparse sets isSparse: true.
Step 2: Shared unmerged path decode
Relay parseUnmergedEntry must decodeGitCQuotedPath the path (from src/shared/git-cquoted-path.ts). Replace existsSync + catch-modified with the same ENOENT/ENOTDIR rule as status-conflict-entries.ts (read that file fully; copy the probe).
Verify: add a quoted-path fixture ("path with space" / cquoted) on the relay status tests.
Step 3: Delete drifted helpers
No second parseWorktreeList body in git-handler-utils.ts.
Verify: rg "function parseWorktreeList" src shows one implementation. rg "function parseUnmergedEntry" src shows one implementation or a thin wrapper.
Test plan
- Porcelain
sparseline →isSparseon relay list result. - Without the line → field absent (Git 2.25).
- Cquoted unmerged path decodes.
- existsSync EACCES must not report deleted as modified if desktop treats only ENOENT — match desktop.
- Model after
src/main/git/worktree-list-porcelain.test.tsif present.
Done criteria
-
pnpm tc:nodeexits 0 - Relay list parser understands
sparse - Relay unmerged parser uses
decodeGitCQuotedPath - Tests listed pass
- No files outside the in-scope list
-
plans/README.mdstatus row updated
STOP conditions
- Sharing the parser requires importing Electron from relay.
- Wire consumers require
isSparseboolean (would break Rule 1) — keep it optional/absent.
Maintenance notes
- Reviewer: mixed-version clients ignore unknown
isSparse(Rule 1). - Follow-up: local filesystem sparse probe on SSH if porcelain is old.
git-handler-worktree-ops.tscomments about lockstep copies should be deleted once there is one parser.
Activity
fix(git): parse sparse and cquoted paths on the SSH relay (#18389)
fix(git): parse sparse and cquoted paths on the SSH relay (stablyai#1…