Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix worktree grouping for bare checkouts (#59968)
Anant Goelea87b0579464
diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rsindex 60e49fc39a6..d8dad9fec13 100644--- a/crates/collab/src/db.rs+++ b/crates/collab/src/db.rs@@ -525,6 +525,8 @@ impl RejoinedProject {visible: worktree.visible,abs_path: worktree.abs_path.clone(),root_repo_common_dir: None,+ // todo(collab): Get this field from database+ root_repo_is_linked_worktree: false,}).collect(),collaborators: selfdiff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rsindex c0ea34bf3aa..431350971ce 100644--- a/crates/collab/src/rpc.rs+++ b/crates/collab/src/rpc.rs@@ -1599,6 +1599,8 @@ fn notify_rejoined_projects(abs_path: worktree.abs_path.clone(),root_name: worktree.root_name,root_repo_common_dir: worktree.root_repo_common_dir,+ // todo(collab): Get this field from database+ root_repo_is_linked_worktree: false,updated_entries: worktree.updated_entries,removed_entries: worktree.removed_entries,scan_id: worktree.scan_id,@@ -2007,6 +2009,8 @@ async fn join_project(visible: worktree.visible,abs_path: worktree.abs_path.clone(),root_repo_common_dir: None,+ // todo(collab): Get this field from database+ root_repo_is_linked_worktree: false,}).collect::<Vec<_>>();@@ -2059,6 +2063,8 @@ async fn join_project(abs_path: worktree.abs_path.clone(),root_name: worktree.root_name,root_repo_common_dir: worktree.root_repo_common_dir,+ // todo(collab): Get this field from database+ root_repo_is_linked_worktree: false,updated_entries: worktree.entries,removed_entries: Default::default(),scan_id: worktree.scan_id,diff --git a/crates/project/src/project.rs b/crates/project/src/project.rsindex 12a3a263d2d..7043c243d83 100644--- a/crates/project/src/project.rs+++ b/crates/project/src/project.rs@@ -2148,6 +2148,7 @@ impl Project {visible: true,abs_path: abs_path.to_string(),root_repo_common_dir: None,+ root_repo_is_linked_worktree: false,},client,PathStyle::Posix,diff --git a/crates/project/src/worktree_store.rs b/crates/project/src/worktree_store.rsindex fd63c972f1d..911f9f79f3b 100644--- a/crates/project/src/worktree_store.rs+++ b/crates/project/src/worktree_store.rs@@ -827,6 +827,7 @@ impl WorktreeStore {visible,abs_path: response.canonicalized_path,root_repo_common_dir: response.root_repo_common_dir,+ root_repo_is_linked_worktree: response.root_repo_is_linked_worktree,},client,path_style,@@ -1155,6 +1156,7 @@ impl WorktreeStore {root_repo_common_dir: worktree.root_repo_common_dir().map(|p| p.to_string_lossy().into_owned()),+ root_repo_is_linked_worktree: worktree.root_repo_is_linked_worktree(),}}).collect()@@ -1371,7 +1373,9 @@ impl WorktreeStore {.root_repo_common_dir().map(|dir| crate::git_store::repo_identity_path(dir)).filter(|repo_path| {- *repo_path == folder_path.as_path() || !folder_path.starts_with(*repo_path)+ snapshot.root_repo_is_linked_worktree()+ || *repo_path == folder_path.as_path()+ || !folder_path.starts_with(*repo_path)}).map(Path::to_path_buf).unwrap_or_else(|| folder_path.clone());diff --git a/crates/project/tests/integration/project_tests.rs b/crates/project/tests/integration/project_tests.rsindex 16e948f3a73..da62617d286 100644--- a/crates/project/tests/integration/project_tests.rs+++ b/crates/project/tests/integration/project_tests.rs@@ -12070,6 +12070,188 @@ async fn test_project_group_keys_remain_distinct_for_sibling_repo_subdirectories);}+fn project_group_key_paths(project: &Entity<Project>, cx: &TestAppContext) -> Vec<PathBuf> {+ project.read_with(cx, |project, cx| {+ ProjectGroupKey::from_project(project, cx)+ .path_list()+ .ordered_paths()+ .cloned()+ .collect()+ })+}++fn project_worktree_paths(+ project: &Entity<Project>,+ cx: &TestAppContext,+) -> (Vec<PathBuf>, Vec<PathBuf>) {+ project.read_with(cx, |project, cx| {+ let paths = project.worktree_paths(cx);+ (+ paths.folder_path_list().ordered_paths().cloned().collect(),+ paths+ .main_worktree_path_list()+ .ordered_paths()+ .cloned()+ .collect(),+ )+ })+}++#[gpui::test]+async fn test_project_group_keys_match_for_bare_repo_linked_worktrees(+ executor: gpui::BackgroundExecutor,+ cx: &mut gpui::TestAppContext,+) {+ init_test(cx);++ let fs = FakeFs::new(executor);+ fs.insert_tree(+ path!("/root"),+ json!({+ "monty": {+ ".git": "gitdir: ./.bare\n",+ ".bare": {+ "HEAD": "ref: refs/heads/main\n",+ "worktrees": {+ "main": {+ "commondir": "../..",+ "gitdir": "/root/monty/main/.git",+ },+ "feature-a": {+ "commondir": "../..",+ "gitdir": "/root/monty/feature-a/.git",+ },+ "feature-b": {+ "commondir": "../..",+ "gitdir": "/root/monty/feature-b/.git",+ },+ },+ },+ "main": {+ ".git": "gitdir: /root/monty/.bare/worktrees/main\n",+ "file.txt": "main",+ },+ "feature-a": {+ ".git": "gitdir: /root/monty/.bare/worktrees/feature-a\n",+ "file.txt": "a",+ },+ "feature-b": {+ ".git": "gitdir: /root/monty/.bare/worktrees/feature-b\n",+ "file.txt": "b",+ },+ },+ }),+ )+ .await;++ let project_root = Project::test(fs.clone(), [path!("/root/monty").as_ref()], cx).await;+ let project_main = Project::test(fs.clone(), [path!("/root/monty/main").as_ref()], cx).await;+ let project_a = Project::test(fs.clone(), [path!("/root/monty/feature-a").as_ref()], cx).await;+ let project_b = Project::test(fs, [path!("/root/monty/feature-b").as_ref()], cx).await;++ project_root+ .update(cx, |project, cx| project.git_scans_complete(cx))+ .await;+ project_main+ .update(cx, |project, cx| project.git_scans_complete(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();++ for project in [&project_root, &project_main, &project_a, &project_b] {+ assert_eq!(+ project_group_key_paths(project, cx),+ vec![PathBuf::from(path!("/root/monty"))]+ );+ }++ assert_eq!(+ project_worktree_paths(&project_root, cx),+ (+ vec![PathBuf::from(path!("/root/monty"))],+ vec![PathBuf::from(path!("/root/monty"))],+ )+ );+ assert_eq!(+ project_worktree_paths(&project_main, cx),+ (+ vec![PathBuf::from(path!("/root/monty/main"))],+ vec![PathBuf::from(path!("/root/monty"))],+ )+ );+ assert_eq!(+ project_worktree_paths(&project_a, cx),+ (+ vec![PathBuf::from(path!("/root/monty/feature-a"))],+ vec![PathBuf::from(path!("/root/monty"))],+ )+ );+ assert_eq!(+ project_worktree_paths(&project_b, cx),+ (+ vec![PathBuf::from(path!("/root/monty/feature-b"))],+ vec![PathBuf::from(path!("/root/monty"))],+ )+ );+}++#[gpui::test]+async fn test_project_group_key_groups_nested_linked_worktree_under_main_repo(+ executor: gpui::BackgroundExecutor,+ cx: &mut gpui::TestAppContext,+) {+ init_test(cx);++ let fs = FakeFs::new(executor);+ fs.insert_tree(+ path!("/root"),+ json!({+ "my-repo": {+ ".git": {},+ "file.txt": "content",+ },+ }),+ )+ .await;++ let linked_worktree_path = PathBuf::from(path!("/root/my-repo/.zed/worktrees/feature"));+ fs.add_linked_worktree_for_repo(+ Path::new(path!("/root/my-repo/.git")),+ false,+ git::repository::Worktree {+ path: linked_worktree_path.clone(),+ ref_name: Some("refs/heads/feature".into()),+ sha: "abc123".into(),+ is_main: false,+ is_bare: false,+ },+ )+ .await;++ let project = Project::test(fs, [linked_worktree_path.as_path()], cx).await;+ project+ .update(cx, |project, cx| project.git_scans_complete(cx))+ .await;+ cx.run_until_parked();++ assert_eq!(+ project_group_key_paths(&project, cx),+ vec![PathBuf::from(path!("/root/my-repo"))]+ );+ assert_eq!(+ project_worktree_paths(&project, cx),+ (+ vec![PathBuf::from(path!("/root/my-repo/.zed/worktrees/feature"))],+ vec![PathBuf::from(path!("/root/my-repo"))],+ )+ );+}+#[gpui::test]async fn test_repository_subfolder_git_status(executor: gpui::BackgroundExecutor,diff --git a/crates/proto/proto/call.proto b/crates/proto/proto/call.protoindex aa79014959a..180d1e5659f 100644--- a/crates/proto/proto/call.proto+++ b/crates/proto/proto/call.proto@@ -231,6 +231,7 @@ message UpdateWorktree {bool is_last_update = 9;string abs_path = 10;optional string root_repo_common_dir = 11;+ bool root_repo_is_linked_worktree = 12;}// deprecateddiff --git a/crates/proto/proto/worktree.proto b/crates/proto/proto/worktree.protoindex 08a1317f6ac..285b4c9056d 100644--- a/crates/proto/proto/worktree.proto+++ b/crates/proto/proto/worktree.proto@@ -41,6 +41,7 @@ message AddWorktreeResponse {uint64 worktree_id = 1;string canonicalized_path = 2;optional string root_repo_common_dir = 3;+ bool root_repo_is_linked_worktree = 4;}message RemoveWorktree {@@ -64,6 +65,7 @@ message WorktreeMetadata {bool visible = 3;string abs_path = 4;optional string root_repo_common_dir = 5;+ bool root_repo_is_linked_worktree = 6;}message ProjectPath {diff --git a/crates/proto/src/proto.rs b/crates/proto/src/proto.rsindex b998300f065..3fbd2352757 100644--- a/crates/proto/src/proto.rs+++ b/crates/proto/src/proto.rs@@ -924,6 +924,7 @@ pub fn split_worktree_update(mut message: UpdateWorktree) -> impl Iterator<Itemroot_name: message.root_name.clone(),abs_path: message.abs_path.clone(),root_repo_common_dir: message.root_repo_common_dir.clone(),+ root_repo_is_linked_worktree: message.root_repo_is_linked_worktree,updated_entries,removed_entries,scan_id: message.scan_id,diff --git a/crates/remote_server/src/headless_project.rs b/crates/remote_server/src/headless_project.rsindex e5b2ef47dea..57f910b5ea1 100644--- a/crates/remote_server/src/headless_project.rs+++ b/crates/remote_server/src/headless_project.rs@@ -537,6 +537,7 @@ impl HeadlessProject {root_repo_common_dir: worktree.root_repo_common_dir().map(|p| p.to_string_lossy().into_owned()),+ root_repo_is_linked_worktree: worktree.root_repo_is_linked_worktree(),}});diff --git a/crates/remote_server/src/remote_editing_tests.rs b/crates/remote_server/src/remote_editing_tests.rsindex cd70c9c2914..46e2eb1eb62 100644--- a/crates/remote_server/src/remote_editing_tests.rs+++ b/crates/remote_server/src/remote_editing_tests.rs@@ -2161,13 +2161,17 @@ async fn test_remote_root_repo_common_dir(cx: &mut TestAppContext, server_cx: &m.unwrap();cx.executor().run_until_parked();- let common_dir = worktree_main.read_with(cx, |worktree, _| {- worktree.snapshot().root_repo_common_dir().cloned()+ let (common_dir, is_linked_worktree) = worktree_main.read_with(cx, |worktree, _| {+ (+ worktree.snapshot().root_repo_common_dir().cloned(),+ worktree.snapshot().root_repo_is_linked_worktree(),+ )});assert_eq!(common_dir.as_deref(),Some(Path::new("/code/main_repo/.git")),);+ assert!(!is_linked_worktree);// Linked worktree: root_repo_common_dir should point to the main repo's .git.let (worktree_linked, _) = project@@ -2178,13 +2182,33 @@ async fn test_remote_root_repo_common_dir(cx: &mut TestAppContext, server_cx: &m.unwrap();cx.executor().run_until_parked();- let common_dir = worktree_linked.read_with(cx, |worktree, _| {- worktree.snapshot().root_repo_common_dir().cloned()+ let (common_dir, is_linked_worktree) = worktree_linked.read_with(cx, |worktree, _| {+ (+ worktree.snapshot().root_repo_common_dir().cloned(),+ worktree.snapshot().root_repo_is_linked_worktree(),+ )});assert_eq!(common_dir.as_deref(),Some(Path::new("/code/main_repo/.git")),);+ assert!(is_linked_worktree);++ let main_worktree_paths = project.read_with(cx, |project, cx| {+ project+ .worktree_paths(cx)+ .main_worktree_path_list()+ .ordered_paths()+ .map(|path| path.to_path_buf())+ .collect::<Vec<_>>()+ });+ assert_eq!(+ main_worktree_paths,+ vec![+ PathBuf::from("/code/main_repo"),+ PathBuf::from("/code/main_repo"),+ ]+ );// No git repo: root_repo_common_dir should be None.let (worktree_no_git, _) = project@@ -2195,10 +2219,14 @@ async fn test_remote_root_repo_common_dir(cx: &mut TestAppContext, server_cx: &m.unwrap();cx.executor().run_until_parked();- let common_dir = worktree_no_git.read_with(cx, |worktree, _| {- worktree.snapshot().root_repo_common_dir().cloned()+ let (common_dir, is_linked_worktree) = worktree_no_git.read_with(cx, |worktree, _| {+ (+ worktree.snapshot().root_repo_common_dir().cloned(),+ worktree.snapshot().root_repo_is_linked_worktree(),+ )});assert_eq!(common_dir, None);+ assert!(!is_linked_worktree);}#[gpui::test]diff --git a/crates/workspace/src/multi_workspace_tests.rs b/crates/workspace/src/multi_workspace_tests.rsindex 323fc10fb01..e0a6bb1e0eb 100644--- a/crates/workspace/src/multi_workspace_tests.rs+++ b/crates/workspace/src/multi_workspace_tests.rs@@ -846,6 +846,7 @@ async fn test_remote_project_root_dir_changes_update_groups(cx: &mut TestAppContupdated_repositories: vec![],removed_repositories: vec![],root_repo_common_dir: None,+ root_repo_is_linked_worktree: false,});});cx.run_until_parked();diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rsindex 2711362dd18..c31385f4553 100644--- a/crates/worktree/src/worktree.rs+++ b/crates/worktree/src/worktree.rs@@ -181,6 +181,7 @@ pub struct Snapshot {entries_by_path: SumTree<Entry>,entries_by_id: SumTree<PathEntry>,root_repo_common_dir: Option<Arc<SanitizedPath>>,+ root_repo_is_linked_worktree: bool,always_included_entries: Vec<Arc<RelPath>>,/// A number that increases every time the worktree begins scanning@@ -421,12 +422,18 @@ impl Worktree {None};- let root_repo_common_dir = if visible {- discover_root_repo_common_dir(&abs_path, fs.as_ref())+ let (root_repo_common_dir, root_repo_is_linked_worktree) = if visible {+ discover_root_repo_metadata(&abs_path, fs.as_ref()).await- .map(SanitizedPath::from_arc)+ .map(|(common_dir, is_linked_worktree)| {+ (+ Some(SanitizedPath::from_arc(common_dir)),+ is_linked_worktree,+ )+ })+ .unwrap_or((None, false))} else {- None+ (None, false)};Ok(cx.new(move |cx: &mut Context<Worktree>| {let mut snapshot = LocalSnapshot {@@ -447,6 +454,7 @@ impl Worktree {root_file_handle,};snapshot.root_repo_common_dir = root_repo_common_dir;+ snapshot.root_repo_is_linked_worktree = root_repo_is_linked_worktree;let worktree_id = snapshot.id();let settings_location = Some(SettingsLocation {@@ -535,6 +543,7 @@ impl Worktree {snapshot.root_repo_common_dir = worktree.root_repo_common_dir.map(|p| SanitizedPath::new_arc(Path::new(&p)));+ snapshot.root_repo_is_linked_worktree = worktree.root_repo_is_linked_worktree;let background_snapshot = Arc::new(Mutex::new((snapshot.clone(),@@ -597,6 +606,8 @@ impl Worktree {}let old_root_repo_common_dir = this.snapshot.root_repo_common_dir.clone();+ let old_root_repo_is_linked_worktree =+ this.snapshot.root_repo_is_linked_worktree;let mut changed_entries: Vec<(Arc<RelPath>, ProjectEntryId, PathChange)> =Vec::new();{@@ -639,6 +650,8 @@ impl Worktree {let is_first_update = !this.received_initial_update;this.received_initial_update = true;if this.snapshot.root_repo_common_dir != old_root_repo_common_dir+ || this.snapshot.root_repo_is_linked_worktree+ != old_root_repo_is_linked_worktree|| (is_first_update && this.snapshot.root_repo_common_dir.is_none()){cx.emit(Event::UpdatedRootRepoCommonDir {@@ -734,6 +747,7 @@ impl Worktree {root_repo_common_dir: self.root_repo_common_dir().map(|p| p.to_string_lossy().into_owned()),+ root_repo_is_linked_worktree: self.root_repo_is_linked_worktree(),}}@@ -1274,13 +1288,28 @@ impl LocalWorktree {) {let repo_changes = self.changed_repos(&self.snapshot, &mut new_snapshot);- new_snapshot.root_repo_common_dir = new_snapshot+ if let Some((common_dir, is_linked_worktree)) = new_snapshot.local_repo_for_work_directory_path(RelPath::empty())- .map(|repo| SanitizedPath::from_arc(repo.common_dir_abs_path.clone()));+ .map(|repo| {+ (+ SanitizedPath::from_arc(repo.common_dir_abs_path.clone()),+ repo.repository_dir_abs_path != repo.common_dir_abs_path,+ )+ })+ {+ new_snapshot.root_repo_common_dir = Some(common_dir);+ new_snapshot.root_repo_is_linked_worktree = is_linked_worktree;+ } else {+ new_snapshot.root_repo_common_dir = None;+ new_snapshot.root_repo_is_linked_worktree = false;+ }- let old_root_repo_common_dir = (self.snapshot.root_repo_common_dir- != new_snapshot.root_repo_common_dir)- .then(|| self.snapshot.root_repo_common_dir.clone());+ let root_repo_metadata_changed = self.snapshot.root_repo_common_dir+ != new_snapshot.root_repo_common_dir+ || self.snapshot.root_repo_is_linked_worktree+ != new_snapshot.root_repo_is_linked_worktree;+ let old_root_repo_common_dir =+ root_repo_metadata_changed.then(|| self.snapshot.root_repo_common_dir.clone());self.snapshot = new_snapshot;if let Some(share) = self.update_observer.as_mut() {@@ -2361,6 +2390,7 @@ impl Snapshot {entries_by_path: Default::default(),entries_by_id: Default::default(),root_repo_common_dir: None,+ root_repo_is_linked_worktree: false,scan_id: 1,completed_scan_id: 0,}@@ -2392,6 +2422,10 @@ impl Snapshot {.map(SanitizedPath::cast_arc_ref)}+ pub fn root_repo_is_linked_worktree(&self) -> bool {+ self.root_repo_is_linked_worktree+ }+fn build_initial_update(&self, project_id: u64, worktree_id: u64) -> proto::UpdateWorktree {let mut updated_entries = self.entries_by_path@@ -2408,6 +2442,7 @@ impl Snapshot {root_repo_common_dir: self.root_repo_common_dir().map(|p| p.to_string_lossy().into_owned()),+ root_repo_is_linked_worktree: self.root_repo_is_linked_worktree,updated_entries,removed_entries: Vec::new(),scan_id: self.scan_id as u64,@@ -2553,11 +2588,21 @@ impl Snapshot {self.entries_by_path.edit(entries_by_path_edits, ());self.entries_by_id.edit(entries_by_id_edits, ());- if let Some(dir) = update+ // A `None` from a completed scan is a real repo removal, whereas a `None`+ // mid-scan may just mean the sender hasn't registered the root repo yet.+ match update.root_repo_common_dir.map(|p| SanitizedPath::new_arc(Path::new(&p))){- self.root_repo_common_dir = Some(dir);+ Some(dir) => {+ self.root_repo_common_dir = Some(dir);+ self.root_repo_is_linked_worktree = update.root_repo_is_linked_worktree;+ }+ None if update.is_last_update => {+ self.root_repo_common_dir = None;+ self.root_repo_is_linked_worktree = false;+ }+ None => {}}self.scan_id = update.scan_id as usize;@@ -2790,6 +2835,7 @@ impl LocalSnapshot {root_repo_common_dir: self.root_repo_common_dir().map(|p| p.to_string_lossy().into_owned()),+ root_repo_is_linked_worktree: self.root_repo_is_linked_worktree,updated_entries,removed_entries,scan_id: self.scan_id as u64,@@ -6621,13 +6667,23 @@ fn resolve_commondir_path(repository_dir_abs_path: &Path, commondir_path: &str)}pub async fn discover_root_repo_common_dir(root_abs_path: &Path, fs: &dyn Fs) -> Option<Arc<Path>> {+ discover_root_repo_metadata(root_abs_path, fs)+ .await+ .map(|(common_dir, _)| common_dir)+}++async fn discover_root_repo_metadata(+ root_abs_path: &Path,+ fs: &dyn Fs,+) -> Option<(Arc<Path>, bool)> {let root_dot_git = root_abs_path.join(DOT_GIT);if !fs.metadata(&root_dot_git).await.is_ok_and(|m| m.is_some()) {return None;}let dot_git_path: Arc<Path> = root_dot_git.into();- let (_, common_dir) = discover_git_paths(&dot_git_path, fs).await;- Some(common_dir)+ let (repository_dir, common_dir) = discover_git_paths(&dot_git_path, fs).await;+ let is_linked_worktree = repository_dir != common_dir;+ Some((common_dir, is_linked_worktree))}async fn discover_git_paths(dot_git_abs_path: &Arc<Path>, fs: &dyn Fs) -> (Arc<Path>, Arc<Path>) {diff --git a/crates/worktree/tests/integration/worktree_tests.rs b/crates/worktree/tests/integration/worktree_tests.rsindex 6a4370539af..1fd7ed5b557 100644--- a/crates/worktree/tests/integration/worktree_tests.rs+++ b/crates/worktree/tests/integration/worktree_tests.rs@@ -4932,6 +4932,7 @@ async fn test_remote_worktree_without_git_emits_root_repo_event_after_first_updavisible: true,abs_path: "/home/user/project".to_string(),root_repo_common_dir: None,+ root_repo_is_linked_worktree: false,},client,PathStyle::Posix,@@ -4989,6 +4990,7 @@ async fn test_remote_worktree_without_git_emits_root_repo_event_after_first_updaupdated_repositories: vec![],removed_repositories: vec![],root_repo_common_dir: None,+ root_repo_is_linked_worktree: false,});});@@ -5027,6 +5029,7 @@ async fn test_remote_worktree_with_git_emits_root_repo_event_when_repo_info_arrivisible: true,abs_path: "/home/user/project".to_string(),root_repo_common_dir: None,+ root_repo_is_linked_worktree: false,},client,PathStyle::Posix,@@ -5081,6 +5084,7 @@ async fn test_remote_worktree_with_git_emits_root_repo_event_when_repo_info_arriupdated_repositories: vec![],removed_repositories: vec![],root_repo_common_dir: Some("/home/user/project/.git".to_string()),+ root_repo_is_linked_worktree: false,});});@@ -5101,6 +5105,94 @@ async fn test_remote_worktree_with_git_emits_root_repo_event_when_repo_info_arri);}+#[gpui::test]+async fn test_remote_worktree_root_repo_metadata_cleared_only_by_completed_scan(+ cx: &mut TestAppContext,+) {+ cx.update(|cx| {+ let store = SettingsStore::test(cx);+ cx.set_global(store);+ });++ let client = AnyProtoClient::new(NoopProtoClient::new());++ // Metadata eagerly seeds the root repo info, as `AddWorktreeResponse` /+ // `WorktreeMetadata` do before the host's scan completes.+ let worktree = cx.update(|cx| {+ Worktree::remote(+ 1,+ clock::ReplicaId::new(1),+ proto::WorktreeMetadata {+ id: 1,+ root_name: "feature-a".to_string(),+ visible: true,+ abs_path: "/home/user/monty/feature-a".to_string(),+ root_repo_common_dir: Some("/home/user/monty/.bare".to_string()),+ root_repo_is_linked_worktree: true,+ },+ client,+ PathStyle::Posix,+ cx,+ )+ });++ let root_repo_metadata = |cx: &mut TestAppContext| {+ worktree.read_with(cx, |worktree, _| {+ let snapshot = worktree.snapshot();+ (+ snapshot.root_repo_common_dir().cloned(),+ snapshot.root_repo_is_linked_worktree(),+ )+ })+ };++ let update = |scan_id: u64, is_last_update: bool| proto::UpdateWorktree {+ project_id: 1,+ worktree_id: 1,+ abs_path: "/home/user/monty/feature-a".to_string(),+ root_name: "feature-a".to_string(),+ updated_entries: vec![],+ removed_entries: vec![],+ scan_id,+ is_last_update,+ updated_repositories: vec![],+ removed_repositories: vec![],+ root_repo_common_dir: None,+ root_repo_is_linked_worktree: false,+ };++ // A mid-scan update without repo info must not clobber the seeded+ // metadata: the sender's scanner may not have registered the repo yet.+ worktree.update(cx, |worktree, _cx| {+ worktree+ .as_remote()+ .unwrap()+ .update_from_remote(update(2, false));+ });+ cx.run_until_parked();++ assert_eq!(+ root_repo_metadata(cx),+ (Some(Arc::from(Path::new("/home/user/monty/.bare"))), true,),+ "mid-scan update without repo info should not clear seeded metadata"+ );++ // A completed scan without repo info is authoritative: the repo is gone.+ worktree.update(cx, |worktree, _cx| {+ worktree+ .as_remote()+ .unwrap()+ .update_from_remote(update(3, true));+ });+ cx.run_until_parked();++ assert_eq!(+ root_repo_metadata(cx),+ (None, false),+ "completed scan without repo info should clear root repo metadata"+ );+}+// Regression test: a remote worktree used to emit `UpdatedEntries` with an// empty changeset (`Arc::default()`), discarding the changed paths. Consumers// that key off those paths - notably the agent's `.agents/skills` refresh -@@ -5152,6 +5244,7 @@ async fn test_remote_worktree_update_entries_carry_changed_paths(cx: &mut TestApvisible: true,abs_path: path!("/root").to_string(),root_repo_common_dir: None,+ root_repo_is_linked_worktree: false,},AnyProtoClient::new(NoopProtoClient::new()),PathStyle::local(),