From dca2560802e7401f5b91bb99c749ad76c5afe383 Mon Sep 17 00:00:00 2001 From: rogue-striker Date: Thu, 29 May 2025 01:56:18 +0530 Subject: [PATCH] fixed git pull error while there is a upstream branch configured --- crates/git/src/repository.rs | 6 ++++++ crates/git_ui/src/git_panel.rs | 18 +++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index 72f24b7285..292a764f5e 100644 --- a/crates/git/src/repository.rs +++ b/crates/git/src/repository.rs @@ -88,6 +88,12 @@ impl Upstream { .and_then(|stripped| stripped.split("/").next()) } + pub fn branch_name(&self) -> Option<&str> { + self.ref_name + .strip_prefix("refs/remotes/") + .and_then(|stripped| stripped.split('/').nth(1)) + } + pub fn stripped_ref_name(&self) -> Option<&str> { self.ref_name.strip_prefix("refs/remotes/") } diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index 6ce92095b9..6601cfdb26 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -1935,7 +1935,16 @@ impl GitPanel { return; }; telemetry::event!("Git Pulled"); - let branch = branch.clone(); + let branch_name: SharedString = if let Some(upstream) = branch.upstream.as_ref() { + if let Some(upstream_branch) = upstream.branch_name() { + SharedString::from(upstream_branch.to_string()) + } else { + branch.name().to_owned().into() + } + } else { + branch.name().to_owned().into() + }; + let remote = self.get_current_remote(window, cx); cx.spawn_in(window, async move |this, cx| { let remote = match remote.await { @@ -1956,12 +1965,7 @@ impl GitPanel { })?; let pull = repo.update(cx, |repo, cx| { - repo.pull( - branch.name().to_owned().into(), - remote.name.clone(), - askpass, - cx, - ) + repo.pull(branch_name.clone(), remote.name.clone(), askpass, cx) })?; let remote_message = pull.await?;