Repository navigation
fix(worktrees): force-remove a clean worktree containing an initialised submodule - #8704
xianjianlf2 wants to merge 1 commit into
Conversation
…ed submodule `git worktree remove` (non-force) categorically refuses any worktree with an initialised submodule — `fatal: working trees containing submodules cannot be moved or removed` — even when the parent and submodule are completely clean. Orca's delete flow proves cleanliness first and then runs a non-force remove, so deleting such a workspace always failed and left the worktree registered and on disk. On that specific refusal, re-prove cleanliness (parent `git status --porcelain --untracked-files=all` reports dirty submodule content as ` M <sub>`) and retry with `--force`. A dirty worktree still surfaces "Worktree has uncommitted or untracked changes." instead of force-deleting. Applies to both the local path and the SSH relay path; both runners pin English git output, so the error-text match is stable. Fixes stablyai#8670 Co-Authored-By: Claude Fable 5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughWorktree removal now detects Git refusals caused by initialized submodules. Non-force removal paths check for uncommitted or untracked content, reject dirty worktrees, and retry clean worktrees with force removal. Force-enabled failures are rethrown without another retry. Shared error normalization and tests cover main and relay removal flows, status checks, command ordering, and branch deletion. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
|
thanks for the PR! will get it in |
|
Taking this over with credit on #9096 — rebased your fix onto current Once #9096 merges we can close this PR. Thanks for the solid approach 🙏 |
|
Thanks for the fix! This has already landed on |
Fixes #8670
Problem
Deleting an Orca workspace fails when its linked worktree contains an initialised submodule, even when both the parent worktree and the submodule are completely clean:
The worktree stays registered and on disk.
Root cause
Git categorically refuses non-force
git worktree removefor any worktree containing an initialised submodule (validate_no_submodulesinbuiltin/worktree.c, since Git 2.17) — cleanliness doesn't matter. Orca's delete flow proves the worktree is clean viagit status --porcelain --untracked-files=alland then runs a non-force remove, so this always failed. Both the local path (src/main/git/worktree.ts) and the SSH relay path (src/relay/git-handler-worktree-remove.ts) are affected.Fix
When the non-force remove fails with that specific refusal:
git status --porcelain --untracked-files=allin the worktree. This gate covers submodule dirtiness — a submodule with modified content, untracked content, or new commits shows up asM <sub>in the parent's porcelain status (verified empirically).git worktree remove --force.The refusal predicate lives in
src/shared/worktree-submodule-removal.tsand is shared by both paths. Error-text matching is safe because both the local git runner and the relay pin English git output (UNTRANSLATED_GIT_OUTPUT_ENV). A caller that already passedforcegets no retry (the first attempt already had--force).Compatibility:
git worktree removeand the refusal message both exist since Git 2.17, below the 2.25 core-workflow baseline; the retry uses no newer syntax, so no capability probe is needed.Testing
--force, original files preserved; caller-forced removal → no double retry.src/main/git/+src/relay/+ worktree IPC suites pass (99 files, 1438 tests).git submodule update --init): removal now succeeds and deletes the merged branch; with a dirtied submodule it refuses and leaves all files intact.🤖 Generated with Claude Code