diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index dc783f1818..54fdb269be 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -4673,13 +4673,18 @@ impl Project { None => return, }; + let relative_repo = match path.strip_prefix(repo.content_path) { + Ok(relative_repo) => relative_repo.to_owned(), + Err(_) => return, + }; + let shared_remote_id = self.shared_remote_id(); let client = self.client.clone(); cx.spawn(|_, mut cx| async move { let diff_base = cx .background() - .spawn(async move { repo.repo.lock().load_index(&path) }) + .spawn(async move { repo.repo.lock().load_index(&relative_repo) }) .await; let buffer_id = buffer.update(&mut cx, |buffer, cx| { diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index 6880ec4ff1..5348f9785f 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -667,13 +667,15 @@ impl LocalWorktree { cx.spawn(|this, mut cx| async move { let text = fs.load(&abs_path).await?; - let diff_base = if let Some(repo) = snapshot.repo_for(&abs_path) { - cx.background() - .spawn({ - let path = path.clone(); - async move { repo.repo.lock().load_index(&path) } - }) - .await + let diff_base = if let Some(repo) = snapshot.repo_for(&path) { + if let Ok(repo_relative) = path.strip_prefix(repo.content_path) { + let repo_relative = repo_relative.to_owned(); + cx.background() + .spawn(async move { repo.repo.lock().load_index(&repo_relative) }) + .await + } else { + None + } } else { None };