Skip to content

Commit 60b3eb3

Browse files
authored
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`
1 parent bbe7c9a commit 60b3eb3

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

crates/git_ui/src/branch_picker.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,30 @@ use workspace::{ModalView, Workspace};
1818
pub fn init(cx: &mut App) {
1919
cx.observe_new(|workspace: &mut Workspace, _, _| {
2020
workspace.register_action(open);
21+
workspace.register_action(switch);
22+
workspace.register_action(checkout_branch);
2123
})
2224
.detach();
2325
}
2426

27+
pub fn checkout_branch(
28+
workspace: &mut Workspace,
29+
_: &zed_actions::git::CheckoutBranch,
30+
window: &mut Window,
31+
cx: &mut Context<Workspace>,
32+
) {
33+
open(workspace, &zed_actions::git::Branch, window, cx);
34+
}
35+
36+
pub fn switch(
37+
workspace: &mut Workspace,
38+
_: &zed_actions::git::Switch,
39+
window: &mut Window,
40+
cx: &mut Context<Workspace>,
41+
) {
42+
open(workspace, &zed_actions::git::Branch, window, cx);
43+
}
44+
2545
pub fn open(
2646
workspace: &mut Workspace,
2747
_: &zed_actions::git::Branch,

crates/git_ui/src/commit_modal.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,17 @@ impl Render for CommitModal {
374374
.on_action(cx.listener(Self::commit))
375375
.on_action(
376376
cx.listener(|this, _: &zed_actions::git::Branch, window, cx| {
377-
this.branch_list.update(cx, |branch_list, cx| {
378-
branch_list.popover_handle.toggle(window, cx);
379-
})
377+
toggle_branch_picker(this, window, cx);
378+
}),
379+
)
380+
.on_action(
381+
cx.listener(|this, _: &zed_actions::git::CheckoutBranch, window, cx| {
382+
toggle_branch_picker(this, window, cx);
383+
}),
384+
)
385+
.on_action(
386+
cx.listener(|this, _: &zed_actions::git::Switch, window, cx| {
387+
toggle_branch_picker(this, window, cx);
380388
}),
381389
)
382390
.elevation_3(cx)
@@ -415,3 +423,13 @@ impl Render for CommitModal {
415423
)
416424
}
417425
}
426+
427+
fn toggle_branch_picker(
428+
this: &mut CommitModal,
429+
window: &mut Window,
430+
cx: &mut Context<'_, CommitModal>,
431+
) {
432+
this.branch_list.update(cx, |branch_list, cx| {
433+
branch_list.popover_handle.toggle(window, cx);
434+
})
435+
}

crates/zed_actions/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ pub mod workspace {
114114
}
115115

116116
pub mod git {
117-
use gpui::action_with_deprecated_aliases;
117+
use gpui::{action_with_deprecated_aliases, actions};
118118

119+
actions!(git, [CheckoutBranch, Switch]);
119120
action_with_deprecated_aliases!(git, Branch, ["branches::OpenRecent"]);
120121
}
121122

0 commit comments

Comments
 (0)