diff --git a/crates/git_ui/src/git_ui.rs b/crates/git_ui/src/git_ui.rs index 01375e600392d2b18b34ec3241aff45c5fad6e67..e12e9142d081c5f083a1f9ba414d7099776f327d 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 Option { 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 c5232a67189949e703a282f9894c71302c2f223a..50d3db65b94040c494b369932a1ac05afc57314a 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) -> Option {