git_ui: Add action to toggle diff base (#62966)

# Objective

- Make it easy to switch Git features between showing uncommitted
changes and all changes on the current branch.

## Solution

- Add `git::ToggleDiffBase`, which toggles the user setting between
`head` and `default_branch`.

## 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 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

---

Release Notes:

- Git: Added an action to toggle the diff base between HEAD and the
default branch.
This commit is contained in:
Ben Kunkle authored and GitHub committed 2026-08-21 16:02:27 +00:00
1 parent 7dcda48fdf
commit f5187eac10
1 file changed
+42
+42
View File
@@ -48,6 +48,8 @@ actions!(
Diff,
/// Shows working changes relative to HEAD.
DiffHead,
/// Toggles the git diff base between HEAD and the default branch.
ToggleDiffBase,
/// Adds files to the git staging area.
Add,
/// Opens a new agent thread with the branch diff for review.
@@ -77,6 +79,19 @@ impl ProjectDiff {
workspace.register_action(|workspace, _: &DiffHead, window, cx| {
Self::deploy_at(workspace, None, window, cx);
});
workspace.register_action(|workspace, _: &ToggleDiffBase, _window, cx| {
settings::update_settings_file(
workspace.app_state().fs.clone(),
cx,
move |settings, _| {
let git = settings.git.get_or_insert_default();
git.diff_base = Some(match git.diff_base.unwrap_or_default() {
GitDiffBaseSetting::Head => GitDiffBaseSetting::DefaultBranch,
GitDiffBaseSetting::DefaultBranch => GitDiffBaseSetting::Head,
});
},
);
});
workspace.register_action(
|workspace, _: &git_actions::ViewUncommittedChanges, window, cx| {
Self::deploy_at(workspace, None, window, cx);
@@ -1117,6 +1132,33 @@ mod tests {
);
});
cx.update(|window, cx| {
window.dispatch_action(ToggleDiffBase.boxed_clone(), cx);
});
cx.run_until_parked();
project.read_with(cx, |project, cx| {
assert_eq!(
project.git_store().read(cx).diff_base(),
GitDiffBaseSetting::DefaultBranch
);
});
cx.update(|window, cx| {
window.dispatch_action(ToggleDiffBase.boxed_clone(), cx);
});
cx.run_until_parked();
project.read_with(cx, |project, cx| {
assert_eq!(
project.git_store().read(cx).diff_base(),
GitDiffBaseSetting::Head
);
});
cx.update(|window, cx| {
window.dispatch_action(ToggleDiffBase.boxed_clone(), cx);
});
cx.run_until_parked();
cx.update(|window, cx| {
window.dispatch_action(Diff.boxed_clone(), cx);
});