Skip to content

Corrupt worktree dirs (not a git repository) are permanently uncollectable by GC #642

Closed

Description

@currentbits

Live evidence (2026-08-21): worktrees/273cd72a-* fails git status with "fatal: not a git repository" — a damaged worktree dir whose thread is archived and past all grace periods.

Both GC paths permanently skip it:

  • gcScan marks it blocked: "git could not read the directory" (electron/worktrees.js:4151), and enforceRetention excludes blocked candidates (worktrees.js:4337), forever.
  • sweepOrphanWorktrees only touches dirs no thread references; this one has a (dead, archived) thread.

So a single interrupted git worktree add leaves a multi-hundred-MB dir that no automatic path can ever remove — the user must find and delete it by hand, and there is no UI surface that even shows it (the GC dialog filters to candidates, and this one is always blocked).

Fix direction: for a worktree dir whose owning thread is archived/transient AND whose .git is unreadable, offer force-removal (fs.rm of the directory + git worktree prune in the repo path) — the branch, if any survived, is untouched by directory removal. At minimum, surface blocked-forever entries in the GC dialog with a manual "Delete directory" action.

Activity

  1. added
    plan:todo
    plan:doing
    plan:done
    and removed
    plan:todo
    plan:doing
    on Aug 21, 2026
  2. currentbits commented on Aug 21, 2026

    @currentbits
    OwnerAuthor

    Implemented on coder/fork-corrupt-worktree-dirs-not-a-git-rep-ab2c6e.

    A worktree git reports as fatal: not a git repository is no longer blocked-forever when the owner is an orphan or a transient (archived / fork):

    • gcScan marks it corrupt (not blocked)
    • enforceRetention / gcClean force-delete the directory (fs.rm + git worktree prune) and clear the thread pointer
    • sweepOrphanWorktrees does the same for unreferenced dirs
    • the branch is left alone
    • Settings → Worktrees pre-selects the row and shows “git could not read the directory · force-delete”

    Still blocked (intentional): dirty trees, other git failures (lock / timeout / missing binary), and corrupt settled keep-N overflow — those are not archived/transient.

    Other git failures stay blocked so a missing git on PATH cannot mass-delete archived checkouts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    plan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions