git_ui: Add context menu to folders in tree view (#59853)
# Objective
- Implement a folder context menu in the git panel tree view.
- Fixes #56020
- Initially I wanted to only fix this, but realized that there is no
right-click action on folders at all and previously right-clicking a
folder had the same effect as clicking in the panel at an empty place.
So I implemented some more, but tried to keep it simple for now.
## Solution
Refactored the `git_ui::git_panel::GitPanel::deploy_entry_context_menu`
in order for it to also work with directories, ensuring that some
options ("Open Diff"/"Open File Diff"/"View File"/"View File History")
are filtered out when opened for a directory.
In order to simplify this and make it clear whether the context menu was
deployed for a directory, a file or a selection of multiple entries, the
`git_ui::git_panel::SelectionTargetKind` enum was introduced.
Some other changes not directly related to this functionality but worth
calling out:
- Fixed the file count in the context menu being incorrect when the same
`RepoPath` appeared in both the "Staged" and "Unstaged" sections, by
deduplicating entries by `RepoPath` in
`GitPanel::effective_status_entries`, so a partially staged file is only
counted, and acted on, once. The same method now also expands a selected
directory into its descendant files.
- Updated `GitPanel::revert_entries` so that discarding multiple
untracked files moves them to the trash instead of deleting them,
consistent with the single-file behaviour. `GitPanel::revert_entry` was
removed, so all discards now go through this method.
- Added `GitPanel::should_unstage`, which decides whether toggling
should stage or unstage the target, taking into account the section the
action was triggered from when grouping by staging status. Previously,
bulk toggling staged the entries unless all of them were already fully
staged, regardless of section.
## Testing
Test both on Linux and macOS, manually, as well as added the following
tests:
- `git_ui::git_panel::tests::test_add_to_gitignore`
- `git_ui::git_panel::tests::test_add_to_git_info_exclude`
-
`git_ui::git_panel::tests::test_revert_directory_trashes_untracked_files`
-
`git_ui::git_panel::tests::test_bulk_toggle_staged_respects_staged_section_intent`
## Self-Review Checklist:
- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable
## Showcase
<img width="2604" height="1938" alt="CleanShot 2026-09-25 at 15 14
40@2x"
src="https://github.com/user-attachments/assets/c44fafde-b28d-4e1e-a07a-e72ae90af1f1"
/>
---
Release Notes:
- Added a folder-specific context menu in the Git Panel's tree view
---------
Co-authored-by: dino <dinojoaocosta@gmail.com>
adc8d7918eSondeyy committed on 9/25/2026, 2:37:43 PM· committed by GitHubparentf8f0a28