From 7aa6f4788d8f3cfdede3c2b41b1bb8258bee1146 Mon Sep 17 00:00:00 2001 From: CharlesChen0823 Date: Fri, 26 Jul 2024 19:20:59 +0800 Subject: [PATCH] regression: Fix a panic when removing git-containing worktree from the project panel (#15256) Follow-up of #14989 Opening a project with git metadata and clicking "Remove from Project" will panic: ![image](https://github.com/user-attachments/assets/ba00dc55-d299-4edc-9a1f-01e92f0dd9ca) Release Notes: - N/A --- crates/project/src/worktree_store.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/project/src/worktree_store.rs b/crates/project/src/worktree_store.rs index dc1a295194..fb79b3f8ea 100644 --- a/crates/project/src/worktree_store.rs +++ b/crates/project/src/worktree_store.rs @@ -96,7 +96,15 @@ impl WorktreeStore { pub fn remove_worktree(&mut self, id_to_remove: WorktreeId, cx: &mut ModelContext) { self.worktrees.retain(|worktree| { if let Some(worktree) = worktree.upgrade() { - worktree.read(cx).id() != id_to_remove + if worktree.read(cx).id() == id_to_remove { + cx.emit(WorktreeStoreEvent::WorktreeRemoved( + worktree.entity_id(), + id_to_remove, + )); + false + } else { + true + } } else { false }