Merge pull request #1223 from zed-industries/update-metadata-when-worktrees-are-removed

Antonio Scandurra created

Update project metadata when releasing a worktree's weak handle

Change summary

crates/project/src/project.rs | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

Detailed changes

crates/project/src/project.rs 🔗

@@ -4088,16 +4088,17 @@ impl Project {
             self.worktrees
                 .push(WorktreeHandle::Strong(worktree.clone()));
         } else {
-            cx.observe_release(&worktree, |this, _, cx| {
-                this.worktrees
-                    .retain(|worktree| worktree.upgrade(cx).is_some());
-                cx.notify();
-            })
-            .detach();
             self.worktrees
                 .push(WorktreeHandle::Weak(worktree.downgrade()));
         }
+
         self.metadata_changed(true, cx);
+        cx.observe_release(&worktree, |this, worktree, cx| {
+            this.remove_worktree(worktree.id(), cx);
+            cx.notify();
+        })
+        .detach();
+
         cx.emit(Event::WorktreeAdded);
         cx.notify();
     }