Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

title_bar: Prefer most specific repository for nested git repos (#51898)

Caio Raphael806a72c54031
diff --git a/crates/git_ui/src/git_ui.rs b/crates/git_ui/src/git_ui.rs
index 01375e60039..e12e9142d08 100644
--- a/crates/git_ui/src/git_ui.rs
+++ b/crates/git_ui/src/git_ui.rs
@@ -295,11 +295,12 @@ pub fn resolve_active_repository(workspace: &Workspace, cx: &App) -> Option<Enti
git_store
.repositories()
.values()
- .find(|repo| {
+ .filter(|repo| {
let repo_path = &repo.read(cx).work_directory_abs_path;
*repo_path == worktree_abs_path
|| worktree_abs_path.starts_with(repo_path.as_ref())
})
+ .max_by_key(|repo| repo.read(cx).work_directory_abs_path.as_os_str().len())
.cloned()
})
})
diff --git a/crates/recent_projects/src/recent_projects.rs b/crates/recent_projects/src/recent_projects.rs
index 95f619f8858..9b0dc2abfe7 100644
--- a/crates/recent_projects/src/recent_projects.rs
+++ b/crates/recent_projects/src/recent_projects.rs
@@ -201,17 +201,19 @@ fn get_branch_for_worktree(
cx: &App,
) -> Option<SharedString> {
let worktree_abs_path = worktree.abs_path();
- for repo in repositories {
- let repo = repo.read(cx);
- if repo.work_directory_abs_path == worktree_abs_path
- || worktree_abs_path.starts_with(&*repo.work_directory_abs_path)
- {
- if let Some(branch) = &repo.branch {
- return Some(SharedString::from(branch.name().to_string()));
- }
- }
- }
- None
+ repositories
+ .iter()
+ .filter(|repo| {
+ let repo_path = &repo.read(cx).work_directory_abs_path;
+ *repo_path == worktree_abs_path || worktree_abs_path.starts_with(repo_path.as_ref())
+ })
+ .max_by_key(|repo| repo.read(cx).work_directory_abs_path.as_os_str().len())
+ .and_then(|repo| {
+ repo.read(cx)
+ .branch
+ .as_ref()
+ .map(|branch| SharedString::from(branch.name().to_string()))
+ })
}
pub fn init(cx: &mut App) {
diff --git a/crates/title_bar/src/title_bar.rs b/crates/title_bar/src/title_bar.rs
index c5232a67189..50d3db65b94 100644
--- a/crates/title_bar/src/title_bar.rs
+++ b/crates/title_bar/src/title_bar.rs
@@ -512,14 +512,15 @@ impl TitleBar {
let git_store = project.git_store().read(cx);
let worktree_path = worktree.read(cx).abs_path();
- for repo in git_store.repositories().values() {
- let repo_path = &repo.read(cx).work_directory_abs_path;
- if worktree_path == *repo_path || worktree_path.starts_with(repo_path.as_ref()) {
- return Some(repo.clone());
- }
- }
-
- None
+ git_store
+ .repositories()
+ .values()
+ .filter(|repo| {
+ let repo_path = &repo.read(cx).work_directory_abs_path;
+ worktree_path == *repo_path || worktree_path.starts_with(repo_path.as_ref())
+ })
+ .max_by_key(|repo| repo.read(cx).work_directory_abs_path.as_os_str().len())
+ .cloned()
}
fn render_remote_project_connection(&self, cx: &mut Context<Self>) -> Option<AnyElement> {