From c0847063773c322c78c1f5ce95270fdba648e2f1 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Tue, 4 Mar 2025 20:09:43 -0700 Subject: [PATCH] git: Improvements to fetch/push/pull (cherry-pick #26041) (#26051) Cherry-picked git: Improvements to fetch/push/pull (#26041) - Add global handlers so these actions can be invoked from the command palette, etc. - Tweak spinner to not show itself until a remote has been selected Release Notes: - N/A Co-authored-by: Cole Miller --- crates/git_ui/src/git_panel.rs | 19 +++++++++++-------- crates/git_ui/src/git_ui.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index 051bc3a690cc3cba329399bfb6532517c8697a94..3d3952732816b56cff66d22eb8308acfc2d32eb7 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -1359,7 +1359,7 @@ impl GitPanel { cx.notify(); } - fn fetch(&mut self, _: &git::Fetch, _window: &mut Window, cx: &mut Context) { + pub(crate) fn fetch(&mut self, _: &git::Fetch, _window: &mut Window, cx: &mut Context) { let Some(repo) = self.active_repository.clone() else { return; }; @@ -1386,7 +1386,7 @@ impl GitPanel { .detach_and_log_err(cx); } - fn pull(&mut self, _: &git::Pull, window: &mut Window, cx: &mut Context) { + pub(crate) fn pull(&mut self, _: &git::Pull, window: &mut Window, cx: &mut Context) { let Some(repo) = self.active_repository.clone() else { return; }; @@ -1394,7 +1394,6 @@ impl GitPanel { return; }; let branch = branch.clone(); - let guard = self.start_remote_operation(); let remote = self.get_current_remote(window, cx); cx.spawn(move |this, mut cx| async move { let remote = match remote.await { @@ -1410,6 +1409,10 @@ impl GitPanel { } }; + let guard = this + .update(&mut cx, |this, _| this.start_remote_operation()) + .ok(); + let pull = repo.update(&mut cx, |repo, _cx| { repo.pull(branch.name.clone(), remote.name.clone()) })?; @@ -1430,7 +1433,7 @@ impl GitPanel { .detach_and_log_err(cx); } - fn push(&mut self, action: &git::Push, window: &mut Window, cx: &mut Context) { + pub(crate) fn push(&mut self, action: &git::Push, window: &mut Window, cx: &mut Context) { let Some(repo) = self.active_repository.clone() else { return; }; @@ -1438,7 +1441,6 @@ impl GitPanel { return; }; let branch = branch.clone(); - let guard = self.start_remote_operation(); let options = action.options; let remote = self.get_current_remote(window, cx); @@ -1456,6 +1458,10 @@ impl GitPanel { } }; + let guard = this + .update(&mut cx, |this, _| this.start_remote_operation()) + .ok(); + let push = repo.update(&mut cx, |repo, _cx| { repo.push(branch.name.clone(), remote.name.clone(), options) })?; @@ -2708,9 +2714,6 @@ impl Render for GitPanel { .on_action(cx.listener(Self::unstage_all)) .on_action(cx.listener(Self::restore_tracked_files)) .on_action(cx.listener(Self::clean_all)) - .on_action(cx.listener(Self::fetch)) - .on_action(cx.listener(Self::pull)) - .on_action(cx.listener(Self::push)) .when(has_write_access && has_co_authors, |git_panel| { git_panel.on_action(cx.listener(Self::toggle_fill_co_authors)) }) diff --git a/crates/git_ui/src/git_ui.rs b/crates/git_ui/src/git_ui.rs index 3015143902656a4a76a202d08ea45941b2b8c37b..6e5e85f73e879ba71a64e8ba11e6367d0d72c023 100644 --- a/crates/git_ui/src/git_ui.rs +++ b/crates/git_ui/src/git_ui.rs @@ -4,6 +4,7 @@ use git_panel_settings::GitPanelSettings; use gpui::App; use project_diff::ProjectDiff; use ui::{ActiveTheme, Color, Icon, IconName, IntoElement}; +use workspace::Workspace; pub mod branch_picker; mod commit_modal; @@ -19,6 +20,34 @@ pub fn init(cx: &mut App) { branch_picker::init(cx); cx.observe_new(ProjectDiff::register).detach(); commit_modal::init(cx); + + cx.observe_new(|workspace: &mut Workspace, _, _| { + workspace.register_action(|workspace, fetch: &git::Fetch, window, cx| { + let Some(panel) = workspace.panel::(cx) else { + return; + }; + panel.update(cx, |panel, cx| { + panel.fetch(fetch, window, cx); + }); + }); + workspace.register_action(|workspace, push: &git::Push, window, cx| { + let Some(panel) = workspace.panel::(cx) else { + return; + }; + panel.update(cx, |panel, cx| { + panel.push(push, window, cx); + }); + }); + workspace.register_action(|workspace, pull: &git::Pull, window, cx| { + let Some(panel) = workspace.panel::(cx) else { + return; + }; + panel.update(cx, |panel, cx| { + panel.pull(pull, window, cx); + }); + }); + }) + .detach(); } // TODO: Add updated status colors to theme