Log error if worktree fails to relativize git repo path (#6693)

This is a follow-up to #6459. It logs the error instead of silently
skipping it.

Release Notes:

- N/A
This commit is contained in:
Thorsten Ball 2024-01-25 11:27:50 +01:00 committed by GitHub
commit dd3ec15acc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -194,12 +194,14 @@ impl AsRef<Path> for RepositoryWorkDirectory {
pub struct WorkDirectoryEntry(ProjectEntryId); pub struct WorkDirectoryEntry(ProjectEntryId);
impl WorkDirectoryEntry { impl WorkDirectoryEntry {
pub(crate) fn relativize(&self, worktree: &Snapshot, path: &Path) -> Option<RepoPath> { pub(crate) fn relativize(&self, worktree: &Snapshot, path: &Path) -> Result<RepoPath> {
worktree.entry_for_id(self.0).and_then(|entry| { let entry = worktree
path.strip_prefix(&entry.path) .entry_for_id(self.0)
.ok() .ok_or_else(|| anyhow!("entry not found"))?;
.map(move |path| path.into()) let path = path
}) .strip_prefix(&entry.path)
.map_err(|_| anyhow!("could not relativize {:?} against {:?}", path, entry.path))?;
Ok(path.into())
} }
} }
@ -970,12 +972,13 @@ impl LocalWorktree {
let mut index_task = None; let mut index_task = None;
let snapshot = this.update(&mut cx, |this, _| this.as_local().unwrap().snapshot())?; let snapshot = this.update(&mut cx, |this, _| this.as_local().unwrap().snapshot())?;
if let Some(repo) = snapshot.repository_for_path(&path) { if let Some(repo) = snapshot.repository_for_path(&path) {
if let Some(repo_path) = repo.work_directory.relativize(&snapshot, &path) { if let Some(repo_path) = repo.work_directory.relativize(&snapshot, &path).log_err()
if let Some(repo) = snapshot.git_repositories.get(&*repo.work_directory) { {
let repo = repo.repo_ptr.clone(); if let Some(git_repo) = snapshot.git_repositories.get(&*repo.work_directory) {
let git_repo = git_repo.repo_ptr.clone();
index_task = Some( index_task = Some(
cx.background_executor() cx.background_executor()
.spawn(async move { repo.lock().load_index_text(&repo_path) }), .spawn(async move { git_repo.lock().load_index_text(&repo_path) }),
); );
} }
} }