Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
git_ui: Add action to toggle diff base (#62966)
Ben Kunkle1ea16c1ab9dd
diff --git a/crates/git_ui/src/project_diff.rs b/crates/git_ui/src/project_diff.rsindex f300fe7ca7d..3d76d4a7d84 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);});