From 7e21e0f0eb43ed57e8b2371f7c05b2e6a8c93e34 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 18 Dec 2023 13:05:25 +0200 Subject: [PATCH] Do not panic on non-worktree file indexing --- crates/project/src/worktree.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index c721d127ad..8b9fdd2c65 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -963,12 +963,19 @@ impl LocalWorktree { let mut index_task = None; let snapshot = this.read_with(&cx, |this, _| this.as_local().unwrap().snapshot()); if let Some(repo) = snapshot.repository_for_path(&path) { - let repo_path = repo.work_directory.relativize(&snapshot, &path).unwrap(); - if let Some(repo) = snapshot.git_repositories.get(&*repo.work_directory) { - let repo = repo.repo_ptr.clone(); - index_task = Some( - cx.background() - .spawn(async move { repo.lock().load_index_text(&repo_path) }), + if let Some(repo_path) = repo.work_directory.relativize(&snapshot, &path) { + if let Some(repo) = snapshot.git_repositories.get(&*repo.work_directory) { + let repo = repo.repo_ptr.clone(); + index_task = Some( + cx.background() + .spawn(async move { repo.lock().load_index_text(&repo_path) }), + ); + } + } else { + log::warn!( + "Skipping loading index text from path {:?} is not in repository {:?}", + path, + repo.work_directory, ); } }