diff --git a/crates/git/src/git.rs b/crates/git/src/git.rs index 003d455d87..fb7bca2144 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.rs index 4c3255e2da..0bcec87de3 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) { + pub(crate) fn push( + &mut self, + force_push: bool, + select_remote: bool, + window: &mut Window, + cx: &mut Context, + ) { 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, ) -> impl Future>> + use<> { @@ -2182,8 +2189,13 @@ impl GitPanel { let repo = repo.context("No active repository")?; let current_remotes: Vec = 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.rs index 6da3fe8bb5..2429145720 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::(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()) })) })