From 94e4aa626da223577b993dfcacd9f3894546efb8 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Mon, 10 Mar 2025 20:53:46 -0600 Subject: [PATCH] Use current upstream for permalink to line (#26398) Release Notes: - git: Copy permalink to line now uses the upstream of the current branch instead of "origin" --- crates/git/src/repository.rs | 8 ++++++++ crates/project/src/buffer_store.rs | 12 +++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index 99a490c0dca094e892971436b61988a8adcb0864..18ccd5c4001f827eefe69212b146fa1fd45a0b10 100644 --- a/crates/git/src/repository.rs +++ b/crates/git/src/repository.rs @@ -56,6 +56,14 @@ pub struct Upstream { pub tracking: UpstreamTracking, } +impl Upstream { + pub fn remote_name(&self) -> Option<&str> { + self.ref_name + .strip_prefix("refs/remotes/") + .and_then(|stripped| stripped.split("/").next()) + } +} + #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] pub enum UpstreamTracking { /// Remote ref not present in local repository. diff --git a/crates/project/src/buffer_store.rs b/crates/project/src/buffer_store.rs index e514d91ec228d395a6f96cfa35867c93e6f02014..f4ae0ce05a468dafb663c56fb5a879d326e7e731 100644 --- a/crates/project/src/buffer_store.rs +++ b/crates/project/src/buffer_store.rs @@ -1692,11 +1692,17 @@ impl BufferStore { Err(e) => return Task::ready(Err(e)), }; + let remote = repo_entry + .branch() + .and_then(|b| b.upstream.as_ref()) + .and_then(|b| b.remote_name()) + .unwrap_or("origin") + .to_string(); + cx.spawn(|cx| async move { - const REMOTE_NAME: &str = "origin"; let origin_url = repo - .remote_url(REMOTE_NAME) - .ok_or_else(|| anyhow!("remote \"{REMOTE_NAME}\" not found"))?; + .remote_url(&remote) + .ok_or_else(|| anyhow!("remote \"{remote}\" not found"))?; let sha = repo .head_sha()