Skip to content

Fix git worktree popup popup no worktree when opened in a project#55053

Merged
maxbrunsfeld merged 4 commits intozed-industries:mainfrom
OmChillure:fix-git-worktree-popup-lists-no-worktree
May 5, 2026
Merged

Fix git worktree popup popup no worktree when opened in a project#55053
maxbrunsfeld merged 4 commits intozed-industries:mainfrom
OmChillure:fix-git-worktree-popup-lists-no-worktree

Conversation

@OmChillure
Copy link
Copy Markdown
Contributor

Summary

Fixes the git: worktree popup showing no worktrees when a project is opened at the parent of a .bare directory (the common bare-clone-with-sibling-worktrees layout).

What's fixed

  • crates/git/src/repository.rs

    • New git_binary_for_worktree_list helper that uses repository.path() as the working directory when workdir() is None.
    • worktrees() switched to the new helper.
    • parse_worktrees_from_str accepts bare entries without a HEAD line.
  • Tests

    • Unit test: parser handles a bare entry with no HEAD followed by a normal worktree entry.
    • Integration test: full .git-file → .bare + sibling worktrees layout (main, feature-a, feature-b) is listed correctly via the real git binary.

UI rendering already gates on empty sha (worktree_picker.rs uses .when(!sha.is_empty(), ...)), so the bare entry's empty sha renders without artifacts.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments — N/A, no unsafe
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable — same single git worktree list --porcelain invocation, no extra work

Closes #54824

Video

Screencast.from.2026-04-28.09-43-45.webm

Release Notes:

  • Fixed the git: worktree popup listing no worktrees when a project was opened at the parent of a .bare directory (bare-clone-with-sibling-worktrees layout).

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 28, 2026
@zed-community-bot zed-community-bot Bot added the guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions label Apr 28, 2026
@danilo-leal
Copy link
Copy Markdown
Member

Heya, thanks for the PR! How different is this solution from #55044 which was opened just a few hours before yours? It feels like different takes for the same problem.

@OmChillure
Copy link
Copy Markdown
Contributor Author

Heya, thanks for the PR! How different is this solution from #55044 which was opened just a few hours before yours? It feels like different takes for the same problem.

Hey @danilo-leal — these two PRs are actually fixing different bugs in the same bare worktree layout:

  • Fix bare worktree identity in worktree switcher #55044 fixes #54830: the popup does show entries, but switching to a worktree renames the whole project to e.g. feature-a and shows the wrong worktree label. That's a path identity issue in original_repo_path.

  • This PR fixes #54824: the popup shows an empty list in the first place when Zed is opened at the project root (~/Dev/monty/). The root cause is that git: worktree was being invoked without a working directory, so bare repos with no workdir() returned nothing. I also updated the parser to handle bare entries that have no HEAD line.

Both were reported by the same user with the same repo layout, which makes them look related but I believe they are solving two different bugs?

@saberoueslati
Copy link
Copy Markdown
Contributor

saberoueslati commented Apr 28, 2026

@OmChillure for a second your PR was attempting to close the same issue I worked on in the Github UI that's why @danilo-leal was confused I guess

@maxbrunsfeld
Copy link
Copy Markdown
Collaborator

@OmChillure I merged main and made some changes to this. I took your git_binary_for_worktree_list function and made that the new git_binary function that is used anytime we don't require a worktree. I renamed the old git_binary to git_binary_with_worktree, for use in methods like status that shouldn't be run if we don't have a worktree.

@maxbrunsfeld
Copy link
Copy Markdown
Collaborator

/cherry-pick preview

@maxbrunsfeld maxbrunsfeld added this pull request to the merge queue May 5, 2026
Merged via the queue into zed-industries:main with commit 358d88d May 5, 2026
31 checks passed
maxbrunsfeld added a commit that referenced this pull request May 5, 2026
…5053) (cherry-pick to preview) (#55790)

Cherry-pick of #55053 to preview

----
## Summary

Fixes the `git: worktree` popup showing no worktrees when a project is
opened at the parent of a `.bare` directory (the common
bare-clone-with-sibling-worktrees layout).

## What's fixed

- `crates/git/src/repository.rs`
- New `git_binary_for_worktree_list` helper that uses
`repository.path()` as the working directory when `workdir()` is `None`.
  - `worktrees()` switched to the new helper.
- `parse_worktrees_from_str` accepts bare entries without a `HEAD` line.
  
- Tests
- Unit test: parser handles a bare entry with no `HEAD` followed by a
normal worktree entry.
- Integration test: full `.git`-file → `.bare` + sibling worktrees
layout (`main`, `feature-a`, `feature-b`) is listed correctly via the
real `git` binary.

UI rendering already gates on empty sha (`worktree_picker.rs` uses
`.when(!sha.is_empty(), ...)`), so the bare entry's empty sha renders
without artifacts.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments — N/A, no `unsafe`
- [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 — same
single `git worktree list --porcelain` invocation, no extra work

#### Closes #54824

Video 

[Screencast from 2026-04-28

09-43-45.webm](https://github.com/user-attachments/assets/e414d546-eb61-4cb2-857e-3c392f416f96)


Release Notes:

- Fixed the `git: worktree` popup listing no worktrees when a project
was opened at the parent of a `.bare` directory
(bare-clone-with-sibling-worktrees layout).

---------

Co-authored-by: Max Brunsfeld <[email protected]>

Co-authored-by: Om Chillure <[email protected]>
Co-authored-by: Max Brunsfeld <[email protected]>
ebaah46 pushed a commit to ebaah46/zed that referenced this pull request May 6, 2026
…d-industries#55053)

## Summary

Fixes the `git: worktree` popup showing no worktrees when a project is
opened at the parent of a `.bare` directory (the common
bare-clone-with-sibling-worktrees layout).

## What's fixed

- `crates/git/src/repository.rs`
- New `git_binary_for_worktree_list` helper that uses
`repository.path()` as the working directory when `workdir()` is `None`.
  - `worktrees()` switched to the new helper.
- `parse_worktrees_from_str` accepts bare entries without a `HEAD` line.
  
- Tests
- Unit test: parser handles a bare entry with no `HEAD` followed by a
normal worktree entry.
- Integration test: full `.git`-file → `.bare` + sibling worktrees
layout (`main`, `feature-a`, `feature-b`) is listed correctly via the
real `git` binary.

UI rendering already gates on empty sha (`worktree_picker.rs` uses
`.when(!sha.is_empty(), ...)`), so the bare entry's empty sha renders
without artifacts.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments — N/A, no `unsafe`
- [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 — same
single `git worktree list --porcelain` invocation, no extra work

#### Closes zed-industries#54824

Video 

[Screencast from 2026-04-28
09-43-45.webm](https://github.com/user-attachments/assets/e414d546-eb61-4cb2-857e-3c392f416f96)


Release Notes:

- Fixed the `git: worktree` popup listing no worktrees when a project
was opened at the parent of a `.bare` directory
(bare-clone-with-sibling-worktrees layout).

---------

Co-authored-by: Max Brunsfeld <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git: worktree popup lists no worktrees when opened in the project root

5 participants