Files
zed/crates/git
Kirill Bulatov 3b6227877b Show a repository's closed checkouts in the worktree picker (#67426)
Follow-up to https://github.com/zed-industries/zed/pull/67187

After a restart Zed reopens only each window's active workspace, so the
title-bar worktree picker and the sidebar project menu could not switch
to the repository's other checkouts.

The worktree picker now also lists, as closed rows:
- Delta checkouts of the same source repository, found in
`<source>/.delta/worktrees` and in Delta's managed stores.
- The source repository's own checkout, as "main worktree".
- Linked worktrees registered with the source or with its Delta clones.

Enter opens the checkout, or switches to it when it is already open, and
the secondary action opens it in a new window.
The sidebar project menu gets "Switch Worktree…", which opens the same
picker in the group's workspace.

The picker also opens with what the window already knows, instead of a
single row that the rest of the list replaces later:
- The repository scan records the remote default branch from its
existing `git for-each-ref` call, so the create row reads "based on
origin/main" from the first frame instead of switching from "main" after
a git round trip.
- Git rows come from the repository snapshot; the picker still asks git
when it opens and redraws only if the answer differs.
- Closed rows are read from disk when the picker opens and arrive in one
step.

Discovery reads only the store folders and git's worktree registries,
and refuses symlinks and special files.
A store checkout is listed only when its git directory is where Delta
puts that checkout's clone, so a folder Delta renamed aside, or a copy
in another namespace, is not offered.
Git runs only for the "main worktree" row and for reftable HEADs, with
the untrusted-repository options, a 5s timeout and kill on drop.

Known limitations:
- Checkouts mounted into a folder of the user's choosing (`delta
worktree mount <ref> <dir>`) are not listed, because finding them means
reading `.delta/clones`, which tracked content can control.
- A project group with no open workspace after a restart needs Focus
Project before "Switch Worktree…" appears.
- With AI disabled, switching away from the window's starting workspace
drops it without a save prompt, as the existing worktree switch does.
- Closed rows load after the picker opens, so the list grows once when
they arrive.
- The first frame's current-checkout row differs from git's when the
path is spelled differently (symlink, letter case, SSH to Windows), for
an unborn HEAD or orphan branch, and for a `core.bare` folder opened as
the project; the refresh corrects it.
- Collab guests who join after the host's last update see the create
row's base change once, as before.

Release Notes:

- N/A (Nighlty only)
2026-11-24 15:46:28 +00:00
..