From 2f09a4af16637bb2970f583220cdcdd597605cad Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 22 Jun 2022 10:26:10 +0200 Subject: [PATCH] Update project metadata when releasing a worktree's weak handle When a project was getting unshared, we would remove invisible worktrees from the project's state without notifying the server, which was causing the randomized tests to fail. This commit calls `Project::remove_worktree` when a worktree's handle gets released. Doing so ensures that we update both our local metadata database as well as the state on the server. --- crates/project/src/project.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 4f8a40a04370cd713f276fc9e429fe45e62701b3..1eb7616d926f45dcde622924b229814a34e817c2 100644 --- a/crates/project/src/project.rs +++ b/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(); }