From 60b3eb3f766704b288950e0522ff650fc47e4ab1 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 7 Mar 2025 16:02:57 -0800 Subject: [PATCH] Add git branch switching aliases (#26315) This gives us _very_ rudimentary support for `git switch` and `git checkout` now, by making them aliases for our existing `git::branch` call. Release Notes: - Git Beta: Added `git::Switch` and `git::CheckoutBranch` as aliases for the existing `git::Branch` --- crates/git_ui/src/branch_picker.rs | 20 ++++++++++++++++++++ crates/git_ui/src/commit_modal.rs | 24 +++++++++++++++++++++--- crates/zed_actions/src/lib.rs | 3 ++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/crates/git_ui/src/branch_picker.rs b/crates/git_ui/src/branch_picker.rs index bd98c5af0d..9c81b62ff1 100644 --- a/crates/git_ui/src/branch_picker.rs +++ b/crates/git_ui/src/branch_picker.rs @@ -18,10 +18,30 @@ use workspace::{ModalView, Workspace}; pub fn init(cx: &mut App) { cx.observe_new(|workspace: &mut Workspace, _, _| { workspace.register_action(open); + workspace.register_action(switch); + workspace.register_action(checkout_branch); }) .detach(); } +pub fn checkout_branch( + workspace: &mut Workspace, + _: &zed_actions::git::CheckoutBranch, + window: &mut Window, + cx: &mut Context, +) { + open(workspace, &zed_actions::git::Branch, window, cx); +} + +pub fn switch( + workspace: &mut Workspace, + _: &zed_actions::git::Switch, + window: &mut Window, + cx: &mut Context, +) { + open(workspace, &zed_actions::git::Branch, window, cx); +} + pub fn open( workspace: &mut Workspace, _: &zed_actions::git::Branch, diff --git a/crates/git_ui/src/commit_modal.rs b/crates/git_ui/src/commit_modal.rs index ff7b2a295d..b2e751bd41 100644 --- a/crates/git_ui/src/commit_modal.rs +++ b/crates/git_ui/src/commit_modal.rs @@ -374,9 +374,17 @@ impl Render for CommitModal { .on_action(cx.listener(Self::commit)) .on_action( cx.listener(|this, _: &zed_actions::git::Branch, window, cx| { - this.branch_list.update(cx, |branch_list, cx| { - branch_list.popover_handle.toggle(window, cx); - }) + toggle_branch_picker(this, window, cx); + }), + ) + .on_action( + cx.listener(|this, _: &zed_actions::git::CheckoutBranch, window, cx| { + toggle_branch_picker(this, window, cx); + }), + ) + .on_action( + cx.listener(|this, _: &zed_actions::git::Switch, window, cx| { + toggle_branch_picker(this, window, cx); }), ) .elevation_3(cx) @@ -415,3 +423,13 @@ impl Render for CommitModal { ) } } + +fn toggle_branch_picker( + this: &mut CommitModal, + window: &mut Window, + cx: &mut Context<'_, CommitModal>, +) { + this.branch_list.update(cx, |branch_list, cx| { + branch_list.popover_handle.toggle(window, cx); + }) +} diff --git a/crates/zed_actions/src/lib.rs b/crates/zed_actions/src/lib.rs index d78c5d86ba..d32582b5b5 100644 --- a/crates/zed_actions/src/lib.rs +++ b/crates/zed_actions/src/lib.rs @@ -114,8 +114,9 @@ pub mod workspace { } pub mod git { - use gpui::action_with_deprecated_aliases; + use gpui::{action_with_deprecated_aliases, actions}; + actions!(git, [CheckoutBranch, Switch]); action_with_deprecated_aliases!(git, Branch, ["branches::OpenRecent"]); }