diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index fd12dafa98..e3807a8fd6 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 4ecb4a8829..0728d87cb3 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -2259,7 +2259,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_remote(false, window, cx); cx.spawn_in(window, async move |this, cx| { let remote = match remote.await { @@ -2280,12 +2289,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?;