# Prevent multibuffer items from switching active repository \(\#58795\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 418f89714891f9d8105a3e92e60b9a7a5084d232

Requested commit: 418f89714891f9d8105a3e92e60b9a7a5084d232

Commit: 418f89714891f9d8105a3e92e60b9a7a5084d232

Tree: e1ebdda1b01c87cc8d25a3e820f010134acbc5f2

Author: mengh04

Committer: GitHub

## Message

```
Prevent multibuffer items from switching active repository (#58795)

Fixes the git panel's active repository being silently overridden by the
cursor position in `ProjectDiff`.

Closes #58792
Closes #61530

## Summary

When a multi-buffer item (e.g. `ProjectDiff`) gains focus, the workspace
calls `set_active_repo_for_path` with the cursor's project path to
automatically switch the active git repository. This was safe when
multi-buffer items returned `None` from `active_project_path`, but PR
#57236 changed `ProjectDiff` to return the cursor-based path (for
project panel highlighting), inadvertently allowing the cursor position
to override the user's explicit repository selection.

Fix the issue by restoring the `Singleton` guard that was removed in PR
#57236: only call `set_active_repo_for_path` when the active item is
backed by a single buffer.

## Changes

- **`workspace.rs`**: Only call `set_active_repo_for_path` when the
active item's `buffer_kind` is `Singleton`. Multi-buffer items (e.g.
`ProjectDiff`, diagnostics, search results) span multiple repositories,
so their cursor position should not trigger an automatic repository
switch.

## Before


https://github.com/user-attachments/assets/6ca4fa61-b42a-447b-9de7-8b6ec1f1181a


## After


https://github.com/user-attachments/assets/9b045ad9-2bb5-4862-ac45-41e9fdd3dc96

Closes #58792

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:

- Fixed the Git panel unexpectedly switching repositories when viewing
changes in multi-repository projects.

---------

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
Co-authored-by: dino <dinojoaocosta@gmail.com>
```

## Parents

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

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