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.
This commit is contained in:
Antonio Scandurra 2022-06-22 10:26:10 +02:00
parent 484e98c0bb
commit 2f09a4af16

View file

@ -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();
}