Skip to content

fix(git): remove worktree folders Finder leaves behind after removal - #685

Merged
lastobelus merged 1 commit into
lastcode/mainfrom
lastcode/fix-worktree-remove-ds-store-orphans
Nov 10, 2026
Merged

lastobelus merged 1 commit into
lastcode/mainfrom
lastcode/fix-worktree-remove-ds-store-orphans

Conversation

@lastobelus

@lastobelus lastobelus commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Problem

On macOS, Finder can recreate a .DS_Store file inside a worktree folder while Git is removing it. Git then unregisters the worktree but can't delete the folder, because it isn't empty. The result is an orphaned folder that later storage cleanup keeps.

Refs #676. This stops one source of new orphaned folders. Classifying orphans that already exist is still tracked in that issue, so this PR doesn't close it.

Fix

Worktree removal now finishes the job when only Finder metadata is left.

  • Registration check: if git worktree remove fails after deleting the folder's .git file, we list worktrees and compare canonical paths. The leftover cleanup runs only when the folder is no longer registered. Recovery requires NUL-separated output; Git versions that don't support it keep the original failure.
  • Shared .DS_Store rule: a new isDisposableFinderMetadata helper treats a .DS_Store as disposable only if it is a regular file. Directories with that name are kept without traversing their contents. Existing link cleanup still unlinks links without following them. Storage cleanup's "has ignored files" check now uses the same helper instead of its own copy.
  • Both paths: leftover cleanup runs after a successful removal and after a failed-but-unregistered one. It unlinks links, deletes regular .DS_Store files, and removes directories left empty.
  • New files survive: if anything else remains (for example a note someone added), it stays on disk and its retention is logged as a warning.
  • Unrelated folders: a Git refusal that leaves .git intact does not trigger cleanup, including foreign or already-pruned worktrees. If the worktree list can't be read or comes back empty or truncated, we keep the original removal failure and leave the folder.

Proof

  • Tests: six original regression cases and five review cases failed before their fixes. All 50 focused cases pass, including a detached worktree that remains registered after partial deletion and is addressed through an alias.
  • Runtime: a standalone run in disposable real repos confirmed that metadata-only remnants were removed and that added notes were kept and logged.
  • CI: Quick CI passed on the exact head.
  • check:changed: format, lint, graphql, knip, and typecheck of the three affected packages passed. The final selected-test run is still running; the previous run passed all 679 tests.

No manifest changed; the unused-patch check is skipped and #677 is untouched.

The commit uses Carry-Group: incubator because it extends cleanup already carried in later groups. Same-base compilation passed with that assignment; upstream-bugfixes conflicts before those dependencies are replayed.

Local review: 3 rounds with gpt-6.1-terra (xhigh) and claude-opus-5-5 (high), approved. Concrete findings were addressed. The remaining hypothetical malformed-successful-Git-output concern was declined: output reads and process completion are awaited, read errors fail, and truncation is rejected.

Implemented with GPT-6.1 Sol (xhigh), Codex harness in T3 Code.

@lastobelus lastobelus changed the title fix(git): finish worktree removal when Finder recreates metadata fix(git): remove worktree folders Finder leaves behind after removal Nov 10, 2026
Recover only when Git deleted the checkout .git file and canonical NUL-separated inventory confirms it is unregistered. Share the regular-file Finder metadata rule with storage cleanup, preserve all other new work, and fail closed for refused or unprovable removal.

Carry-Group: incubator
Carry-Fix: #676
Carry-Observation: Extends leftover removal and Finder metadata cleanup carried in later groups; replay requires incubator.
@lastobelus
lastobelus force-pushed the lastcode/fix-worktree-remove-ds-store-orphans branch from f38bb2e to 098f457 Compare November 10, 2026 00:42
@lastobelus
lastobelus marked this pull request as ready for review November 10, 2026 00:43
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T00:45:31.630199Z 098f457 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lastobelus

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 098f457060

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@lastobelus

Copy link
Copy Markdown
Owner Author

Final local validation on 098f457060f158d2f1e48838798f5b26c306d054: vp run check:changed origin/lastcode/main passed every selected step, including all 680 tests, format, lint, GraphQL generation, knip, and typecheck of the three affected packages.

All 50 focused worktree/Finder cases and exact-head Quick CI also passed. Codex review completed cleanly on this head, with zero unresolved review threads. The final selected-test run mentioned as pending in the description is now complete.

The unused-patch check was skipped because no dependency files changed. #677 is untouched.

@lastobelus
lastobelus merged commit 7f98915 into lastcode/main Nov 10, 2026
25 of 38 checks passed
@lastobelus
lastobelus deleted the lastcode/fix-worktree-remove-ds-store-orphans branch November 10, 2026 00:57
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.

1 participant