Repository navigation
Fix worktree removal blocked by populated submodules (local and SSH paths) - #7354
soichisumi wants to merge 4 commits into
Conversation
📝 WalkthroughWalkthroughThis PR adds detection and handling of "populated submodules" errors during git worktree removal across three layers: the main-process git worktree module, the relay git handler, and the renderer store. When Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant RemovalLogic
participant Git
Caller->>RemovalLogic: request worktree removal
RemovalLogic->>Git: worktree remove
Git-->>RemovalLogic: fails (populated submodules)
RemovalLogic->>RemovalLogic: classify error as submodule-related
RemovalLogic->>Git: status --ignore-submodules=none
Git-->>RemovalLogic: clean (submodules only)
RemovalLogic->>Git: worktree remove --force
Git-->>RemovalLogic: success
RemovalLogic-->>Caller: removal result
Estimated code review effort: 4 out of 5 (touches critical path logic across three components with locale-sensitive error matching and force-retry behavior). Related issues: None specified. Related PRs: None specified. Suggested labels: git, worktree, submodules, bug-fix Suggested reviewers: None specified. 🐰 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 198fb760-9e99-46c6-b8c0-d6bd001ed24f
📒 Files selected for processing (6)
src/main/git/remove-worktree.test.tssrc/main/git/worktree.tssrc/relay/git-handler-worktree-remove-populated-submodules.test.tssrc/relay/git-handler-worktree-remove.tssrc/renderer/src/store/slices/worktrees.test.tssrc/renderer/src/store/slices/worktrees.ts
| // Why: git's own worktree-remove refusal for a populated submodule (raw, | ||
| // unformatted fatal — e.g. surfaced through a path that does not go through | ||
| // the local auto-force recovery, such as the SSH/relay provider) is also | ||
| // safe to retry with force: it fires even on an otherwise-clean worktree, so | ||
| // force here does not risk discarding uncommitted work. | ||
| const SUBMODULE_WORKTREE_REMOVAL_PATTERN = | ||
| /working trees? containing submodules cannot be moved or removed/i | ||
|
|
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect how the dirty-recheck failure is surfaced in main/relay layers.
rg -n -B5 -A15 'isSubmoduleWorktreeRemovalError' src/main/git/worktree.ts src/relay/git-handler-worktree-remove.tsRepository: stablyai/orca
Length of output: 6731
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the renderer classifier, delete-worktree flow, and any separate dirty-worktree handling.
ast-grep outline src/renderer/src/store/slices/worktrees.ts --view expanded
printf '\n--- delete-worktree-flow matches ---\n'
rg -n -A10 -B10 'FORMATTED_DIRTY_WORKTREE_REMOVAL_PATTERN|SUBMODULE_WORKTREE_REMOVAL_PATTERN|force-retry|worktree remove' src/renderer/src -g '*.ts' -g '*.tsx'Repository: stablyai/orca
Length of output: 19959
Narrow the submodule retry classifier
The dirty-recheck path still rethrows the original submodule fatal, so this regex can also mark genuinely dirty removals as force-retryable and expose Force Delete for uncommitted work. Emit a distinct dirty-worktree error before retry classification, or tighten this match to the clean-only submodule case.
|
Thanks for the careful root-cause work, @soichisumi! The delete dialog now confirms with |
Summary
Deleting an Orca worktree of a repository that contains populated (initialized) git submodules fails outright, because
git worktree removerefuses without--force. This PR makes worktree removal auto-recover from that specific refusal on both the local and the relay/SSH-host code paths, and surfaces the existing "Force Delete" retry affordance for the same error in the UI.Why
git worktree remove <path>refuses withfatal: working trees containing submodules cannot be moved or removedwhenever the worktree contains any populated submodule — even when the worktree is otherwise clean. Orca invokes this command without--forceby default, so removal fails outright:Submodule-containing worktrees are common (any repo that vendors dependencies as submodules), so deletion must work.
Root cause:
git worktree removerunscheck_clean_worktree()→validate_no_submodules()only whenforce == 0(builtin/worktree.c). A single--forcebypasses only the submodule guard (unlikegit worktree move, where--forcedoes not). Orca always invokes the non-force form by default, so any populated submodule blocks removal regardless of cleanliness.What
Three code paths changed:
src/main/git/worktree.ts) —removeWorktree()gains a try/catch auto-force recovery;assertWorktreeCleanForRemoval()gains an optional stricter--ignore-submodules=nonestatus check. The matched invocation pinsLC_ALL=C/LC_MESSAGES=Cbecause git localizes the fatal via gettext.src/relay/git-handler-worktree-remove.ts) —removeWorktreeOp()gains the same auto-force recovery so SSH/remote worktree removal behaves identically to local (satisfies the "must work against local repositories, remote servers, and SSH worktrees" requirement).src/renderer/src/store/slices/worktrees.ts) — the raw submodule fatal is added toFORCE_RETRYABLE_WORKTREE_REMOVAL_MESSAGES, so the "Force Delete" retry button appears for this error (defense-in-depth, and the manual path for the relay locale-miss case in R2).New tests:
src/relay/git-handler-worktree-remove-populated-submodules.test.ts, plus additions tosrc/main/git/remove-worktree.test.tsandsrc/renderer/src/store/slices/worktrees.test.ts.How
On the initial non-force
git worktree removefailure, if the error is the submodule-refusal fatal and the worktree is independently re-verified clean, retry once with--force. The re-verification usesgit status --porcelain --untracked-files=all --ignore-submodules=none, whose command-line--ignore-submodules=noneoverridessubmodule.*.ignore/diff.ignoreSubmodulesconfig — so the auto-force path does not discard uncommitted or untracked work that exists at check time. It only routes around git's blanket submodule refusal for a worktree confirmed clean immediately beforehand. If the re-check finds the worktree dirty, the original error is rethrown rather than forcing (covered by a dedicated data-loss-guard test).The relay executor (
GitExec) has noenvoption, so the locale cannot be pinned there; the relay fatal-text match is therefore locale-dependent on the SSH host, with the renderer force-retry classifier as the fallback (see Residual risk R2).Screenshots
No new UI. The only user-visible change: the common case now succeeds without any prompt, and the existing "Force Delete" retry affordance appears for the submodule-refusal error (previously it matched no retryable pattern).
Test plan
pnpm typecheck— exit 0 (all three projects:tsconfig.node.json,tsconfig.tc.cli.json,tsconfig.tc.web.json).pnpm exec oxlinton all changed files — exit 0, no warnings.pnpm test(full vitest suite) — 22,349 passed, 27 skipped. 108 failures across 34 suites are pre-existing and environment-driven, all in suites that do not import any file changed here (keychain/runtime-auth-servicefail withUnexpected Claude config diron a multi-profile dev box;browser-cookie-import,pty-subprocess/local-pty-provider,orca-runtime-browserscreencast,remote-runtime-clientsocket). Every git / worktree / relay / renderer-worktrees suite passes, including the added tests.pnpm lint— exit 1 only from a pre-existingverify:localization-catalogerror (WorktreeList.tsx:2620references keyauto.components.sidebar.WorktreeList.failedUnnestWorkspace, absent fromen.jsonon cleanorigin/main; unrelated to this PR — none of the 6 changed files touchWorktreeList.tsxoren.json). The oxlint stage passes; the localization-catalog check fails identically onorigin/main.pnpm build— full native/electron build not run locally (heavy, requires the native toolchain); deferred to CI. Local proxypnpm typecheck(all three projects) is green; changes are limited to TypeScript insrc/main,src/relay,src/rendererwith no new deps.AI Review Report
Independent review (Codex, gpt-5.5) of
origin/main..HEAD. Verdict: APPROVE-WITH-NITS, no MUST-FIX.process.envand existing WSL/abort options.--force). Gap: the relay cannot pin locale, so non-English SSH hosts may miss the auto-recovery and fall back to the renderer force-retry UX (R2).git statusand one retry, only on the narrow submodule-fatal path. No hot-path/polling impact.Security Audit
execFile/GitExecexecutors (no shell); the added calls aregit status …andgit worktree remove --force <path>.process.envwithout adding or logging credentials.worktrees:remove/ relayremoveWorktreeOphandlers.--ignore-submodules=nonecleanliness re-check that config cannot defeat; a hidden dirty submodule causes the original error to be rethrown rather than a forced removal (covered by a dedicated test).Residual risks
git status --ignore-submodules=nonesnapshot taken immediately before the forced removal; a concurrent write into a nested submodule in that narrow window is the residual (same shape as any check-then-act removal).LC_ALL=Cto defeat gettext localization; the relay path cannot (itsGitExechas noenvoption), so on a non-English SSH host the relay auto-recovery may not fire — the manual "Force Delete" classifier is the fallback. A futureGitExecenv passthrough would let the relay pin the locale like the local path.X handle: @soichisumi
ELI5
Deleting a worktree with populated submodules failed on local and SSH. Orca recovers from that git refusal and offers Force Delete when needed.