Skip to content

Fix bare worktree identity in worktree switcher#55044

Open
saberoueslati wants to merge 1 commit intozed-industries:mainfrom
saberoueslati:git_ui/bare-worktree-identity
Open

Fix bare worktree identity in worktree switcher#55044
saberoueslati wants to merge 1 commit intozed-industries:mainfrom
saberoueslati:git_ui/bare-worktree-identity

Conversation

@saberoueslati
Copy link
Copy Markdown
Contributor

Context

This fixes #54830, where switching to an existing git worktree in a bare shared-dir layout caused Zed to treat the linked worktree directory as the project root. In a layout like monty/.bare, monty/main, and monty/feature-a, the repository metadata fell back to the linked checkout path because original_repo_path_from_common_dir only recognized .git common dirs. That made the title bar show the project as feature-a and the worktree label as main.

The fix teaches original_repo_path(...) to recognize linked worktrees whose shared git dir is bare and stored under common_dir/worktrees/.... In that case, it now resolves the original repo path to common_dir.parent(), which matches how WorktreeStore already groups these worktrees. I also added targeted regression coverage for both the path resolution helper and the bare-layout project scan path.

Closes #54830

Video of the manual test below :

Screencast.from.2026-04-28.01-31-39.webm

How to Review

  • crates/git/src/repository.rs: Updates original repo path resolution so linked worktrees backed by a bare shared git dir resolve to the shared project root instead of the linked checkout path. Adds unit coverage for normal repos, non-bare linked worktrees, bare linked worktrees, and plain bare repos.
  • crates/project/tests/integration/project_tests.rs: Adds an integration regression test for the .bare + main + feature-a layout and verifies that scanning feature-a produces repository metadata rooted at monty while still identifying the checkout as a linked worktree.

Self-Review Checklist

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Fixed git worktree switching to preserve the shared project identity for repositories using a bare .bare worktree layout

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 28, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git: worktree popup switches the whole project instead of the worktree

1 participant