Fix worktree panic for out-of-worktree files being opened (#3690)

Fixes
https://zed-industries.slack.com/archives/C04S6T1T7TQ/p1702865855729989

Release Notes:

- Fixed certain files excluded from worktrees causing panics when being
opened
This commit is contained in:
Kirill Bulatov 2023-12-18 13:30:46 +02:00 committed by GitHub
commit 11e657803e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -963,7 +963,7 @@ 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_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(
@ -971,6 +971,13 @@ impl LocalWorktree {
.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,
);
}
}
let diff_base = if let Some(index_task) = index_task {