Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
git: Add `PushTo` to select which remote to push (#31482)
CharlesChen0823cf5e76b1b951
diff --git a/crates/git/src/git.rs b/crates/git/src/git.rsindex 003d455d875..fb7bca2144a 100644--- a/crates/git/src/git.rs+++ b/crates/git/src/git.rs@@ -46,6 +46,7 @@ actions!(TrashUntrackedFiles,Uncommit,Push,+ PushTo,ForcePush,Pull,Fetch,diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rsindex 4c3255e2dad..0bcec87de3f 100644--- a/crates/git_ui/src/git_panel.rs+++ b/crates/git_ui/src/git_panel.rs@@ -2025,7 +2025,7 @@ impl GitPanel {};telemetry::event!("Git Pulled");let branch = branch.clone();- let remote = self.get_current_remote(window, cx);+ let remote = self.get_remote(false, window, cx);cx.spawn_in(window, async move |this, cx| {let remote = match remote.await {Ok(Some(remote)) => remote,@@ -2070,7 +2070,13 @@ impl GitPanel {.detach_and_log_err(cx);}- pub(crate) fn push(&mut self, force_push: bool, window: &mut Window, cx: &mut Context<Self>) {+ pub(crate) fn push(+ &mut self,+ force_push: bool,+ select_remote: bool,+ window: &mut Window,+ cx: &mut Context<Self>,+ ) {if !self.can_push_and_pull(cx) {return;}@@ -2095,7 +2101,7 @@ impl GitPanel {_ => None,}};- let remote = self.get_current_remote(window, cx);+ let remote = self.get_remote(select_remote, window, cx);cx.spawn_in(window, async move |this, cx| {let remote = match remote.await {@@ -2169,8 +2175,9 @@ impl GitPanel {!self.project.read(cx).is_via_collab()}- fn get_current_remote(+ fn get_remote(&mut self,+ always_select: bool,window: &mut Window,cx: &mut Context<Self>,) -> impl Future<Output = anyhow::Result<Option<Remote>>> + use<> {@@ -2182,8 +2189,13 @@ impl GitPanel {let repo = repo.context("No active repository")?;let current_remotes: Vec<Remote> = repo.update(&mut cx, |repo, _| {- let current_branch = repo.branch.as_ref().context("No active branch")?;- anyhow::Ok(repo.get_remotes(Some(current_branch.name().to_string())))+ let current_branch = if always_select {+ None+ } else {+ let current_branch = repo.branch.as_ref().context("No active branch")?;+ Some(current_branch.name().to_string())+ };+ anyhow::Ok(repo.get_remotes(current_branch))})??.await??;diff --git a/crates/git_ui/src/git_ui.rs b/crates/git_ui/src/git_ui.rsindex 6da3fe8bb59..24291457205 100644--- a/crates/git_ui/src/git_ui.rs+++ b/crates/git_ui/src/git_ui.rs@@ -75,7 +75,15 @@ pub fn init(cx: &mut App) {return;};panel.update(cx, |panel, cx| {- panel.push(false, window, cx);+ panel.push(false, false, window, cx);+ });+ });+ workspace.register_action(|workspace, _: &git::PushTo, window, cx| {+ let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {+ return;+ };+ panel.update(cx, |panel, cx| {+ panel.push(false, true, window, cx);});});workspace.register_action(|workspace, _: &git::ForcePush, window, cx| {@@ -83,7 +91,7 @@ pub fn init(cx: &mut App) {return;};panel.update(cx, |panel, cx| {- panel.push(true, window, cx);+ panel.push(true, false, window, cx);});});workspace.register_action(|workspace, _: &git::Pull, window, cx| {@@ -379,6 +387,7 @@ mod remote_button {.action("Pull", git::Pull.boxed_clone()).separator().action("Push", git::Push.boxed_clone())+ .action("Push To", git::PushTo.boxed_clone()).action("Force Push", git::ForcePush.boxed_clone())}))})