From f5187eac106cf61ed946fc0beb2a4d02f15a8a64 Mon Sep 17 00:00:00 2001 From: Ben Kunkle Date: Fri, 21 Aug 2026 16:02:27 +0000 Subject: [PATCH] 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. --- crates/git_ui/src/project_diff.rs | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/crates/git_ui/src/project_diff.rs b/crates/git_ui/src/project_diff.rs index f300fe7ca7..3d76d4a7d8 100644 --- a/crates/git_ui/src/project_diff.rs +++ b/crates/git_ui/src/project_diff.rs @@ -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); });