# multiworkspace: Don't destroy workspace when git worktree is detached head \(\#51977\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/2d7c7200cfc4d590bd069974fa7ccc477b0e2cd2)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 2d7c7200cfc4d590bd069974fa7ccc477b0e2cd2

Requested commit: 2d7c7200cfc4d590bd069974fa7ccc477b0e2cd2

Commit: 2d7c7200cfc4d590bd069974fa7ccc477b0e2cd2

Tree: 2fb2589f4496cf6b1b3c2df7dee10b89c9edbc58

Author: Eric Holk

Committer: GitHub

## Message

```
multiworkspace: Don't destroy workspace when git worktree is detached head (#51977)

When a git worktree is in a detached HEAD state (e.g. after `git
checkout --detach`), the workspace for that worktree would disappear
from the sidebar UI, and if the workspace was currently open your UI
would just disappear.

This happened because `parse_worktrees_from_str` silently dropped any
worktree entries without a `branch` line in the porcelain output, which
cascaded through the `linked_worktrees` list and caused
`prune_stale_worktree_workspaces` to remove the workspace.

This PR:
- Makes `Worktree::ref_name` an `Option<SharedString>` so detached
worktrees can be represented
- Renames `Worktree::branch()` to `Worktree::display_name()`, which
returns the branch name when available or the short SHA as a fallback
(mirroring how the title bar already handles detached HEAD for
repositories)
- Updates `parse_worktrees_from_str` to include detached and bare
worktree entries instead of dropping them
- Filters detached worktrees out of the worktree picker UI, preserving
the existing product decision to only show branch-based worktrees there

## Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- N/A
```

## Parents

- [1dfe836d3d37dd53d831d6d6f0e1ccef63304c97](https://git.cafe/gitcafe/zed/commit/1dfe836d3d37dd53d831d6d6f0e1ccef63304c97?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/2d7c7200cfc4d590bd069974fa7ccc477b0e2cd2?format=markdown)
