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.

Fix project grouping for Git repo subdirectories (#57998)

Alisina Bahadori45afbac0a5ab
diff --git a/crates/project/src/worktree_store.rs b/crates/project/src/worktree_store.rs
index f66be5c4249..fd63c972f1d 100644
--- a/crates/project/src/worktree_store.rs
+++ b/crates/project/src/worktree_store.rs
@@ -1369,7 +1369,11 @@ impl WorktreeStore {
let folder_path = snapshot.abs_path().to_path_buf();
let main_path = snapshot
.root_repo_common_dir()
- .map(|dir| crate::git_store::repo_identity_path(dir).to_path_buf())
+ .map(|dir| crate::git_store::repo_identity_path(dir))
+ .filter(|repo_path| {
+ *repo_path == folder_path.as_path() || !folder_path.starts_with(*repo_path)
+ })
+ .map(Path::to_path_buf)
.unwrap_or_else(|| folder_path.clone());
(main_path, folder_path)
})
diff --git a/crates/project/tests/integration/project_tests.rs b/crates/project/tests/integration/project_tests.rs
index c81b3c13e7a..1ef64383eb1 100644
--- a/crates/project/tests/integration/project_tests.rs
+++ b/crates/project/tests/integration/project_tests.rs
@@ -11782,6 +11782,62 @@ async fn test_repository_pending_ops_stage_all(
});
}
+#[gpui::test]
+async fn test_project_group_keys_remain_distinct_for_sibling_repo_subdirectories(
+ executor: gpui::BackgroundExecutor,
+ cx: &mut gpui::TestAppContext,
+) {
+ init_test(cx);
+
+ let fs = FakeFs::new(executor);
+ fs.insert_tree(
+ path!("/root"),
+ json!({
+ "my-repo": {
+ ".git": {},
+ "packages": {
+ "a": { "file.txt": "a" },
+ "b": { "file.txt": "b" },
+ },
+ },
+ }),
+ )
+ .await;
+
+ let project_a =
+ Project::test(fs.clone(), [path!("/root/my-repo/packages/a").as_ref()], cx).await;
+ let project_b = Project::test(fs, [path!("/root/my-repo/packages/b").as_ref()], cx).await;
+
+ project_a
+ .update(cx, |project, cx| project.git_scans_complete(cx))
+ .await;
+ project_b
+ .update(cx, |project, cx| project.git_scans_complete(cx))
+ .await;
+ cx.run_until_parked();
+
+ let key_a = project_a.read_with(cx, |project, cx| ProjectGroupKey::from_project(project, cx));
+ let key_b = project_b.read_with(cx, |project, cx| ProjectGroupKey::from_project(project, cx));
+
+ assert_ne!(key_a, key_b);
+ assert_eq!(
+ key_a
+ .path_list()
+ .ordered_paths()
+ .map(|path| path.as_path())
+ .collect::<Vec<_>>(),
+ vec![Path::new(path!("/root/my-repo/packages/a"))]
+ );
+ assert_eq!(
+ key_b
+ .path_list()
+ .ordered_paths()
+ .map(|path| path.as_path())
+ .collect::<Vec<_>>(),
+ vec![Path::new(path!("/root/my-repo/packages/b"))]
+ );
+}
+
#[gpui::test]
async fn test_repository_subfolder_git_status(
executor: gpui::BackgroundExecutor,
@@ -11833,6 +11889,16 @@ async fn test_repository_subfolder_git_status(
project.repositories(cx).values().next().unwrap().clone()
});
+ let worktree_paths = project.read_with(cx, |project, cx| project.worktree_paths(cx));
+ assert_eq!(
+ worktree_paths
+ .main_worktree_path_list()
+ .ordered_paths()
+ .map(|path| path.as_path())
+ .collect::<Vec<_>>(),
+ vec![Path::new(path!("/root/my-repo/sub-folder-1/sub-folder-2"))]
+ );
+
// Ensure that the git status is loaded correctly
repository.read_with(cx, |repository, _cx| {
assert_eq!(
diff --git a/crates/title_bar/src/title_bar.rs b/crates/title_bar/src/title_bar.rs
index 169aa944e18..f16f07bb894 100644
--- a/crates/title_bar/src/title_bar.rs
+++ b/crates/title_bar/src/title_bar.rs
@@ -268,13 +268,18 @@ impl Render for TitleBar {
};
if let Some(repo_name) = display_name.and_then(|n| n.to_str()) {
- let name = if let Ok(relative) =
- worktree_abs_path.strip_prefix(&*repo.work_directory_abs_path)
- {
- if relative.as_os_str().is_empty() {
- repo_name.to_string()
+ let visible_worktrees_in_repo = self.visible_worktrees_in_repository(repo, cx);
+ let name = if visible_worktrees_in_repo == 1 {
+ if let Ok(relative) =
+ worktree_abs_path.strip_prefix(&*repo.work_directory_abs_path)
+ {
+ if relative.as_os_str().is_empty() {
+ repo_name.to_string()
+ } else {
+ format!("{}/{}", repo_name, relative.display())
+ }
} else {
- format!("{}/{}", repo_name, relative.display())
+ repo_name.to_string()
}
} else {
repo_name.to_string()
@@ -574,6 +579,22 @@ impl TitleBar {
.cloned()
}
+ fn visible_worktrees_in_repository(
+ &self,
+ repository: &project::git_store::Repository,
+ cx: &App,
+ ) -> usize {
+ let repo_path = &repository.work_directory_abs_path;
+ self.project
+ .read(cx)
+ .visible_worktrees(cx)
+ .filter(|worktree| {
+ let worktree_path = worktree.read(cx).abs_path();
+ worktree_path == *repo_path || worktree_path.starts_with(repo_path.as_ref())
+ })
+ .count()
+ }
+
fn render_remote_project_connection(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
let workspace = self.workspace.clone();
diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs
index 46f4c22f35c..b4b955ca872 100644
--- a/crates/worktree/src/worktree.rs
+++ b/crates/worktree/src/worktree.rs
@@ -428,7 +428,6 @@ impl Worktree {
} else {
None
};
-
Ok(cx.new(move |cx: &mut Context<Worktree>| {
let mut snapshot = LocalSnapshot {
ignores_by_parent_abs_path: Default::default(),