diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index aed08e8dc850622cff4dc96631199a039c78ac3f..ba77199d75f624c0dd44ad0b2ba4eec812d9a711 100644 --- a/crates/git/src/repository.rs +++ b/crates/git/src/repository.rs @@ -1326,16 +1326,14 @@ impl GitRepository for RealGitRepository { if path.is_empty() { bail!("empty path has no index text"); } - let entry = index - .get_path(path.as_std_path(), STAGE_NORMAL) - .with_context(|| format!("looking up {path:?} in index"))?; - let oid = if entry.mode != GIT_MODE_SYMLINK { - entry.id - } else { + let Some(entry) = index.get_path(path.as_std_path(), STAGE_NORMAL) else { return Ok(None); }; + if entry.mode == GIT_MODE_SYMLINK { + return Ok(None); + } - let content = repo.find_blob(oid)?.content().to_owned(); + let content = repo.find_blob(entry.id)?.content().to_owned(); Ok(String::from_utf8(content).ok()) } @@ -1353,16 +1351,15 @@ impl GitRepository for RealGitRepository { .spawn(async move { fn logic(repo: &git2::Repository, path: &RepoPath) -> Result> { let head = repo.head()?.peel_to_tree()?; + // git2 unwraps internally on empty paths or `.` if path.is_empty() { return Err(anyhow!("empty path has no committed text")); } - // git2 unwraps internally on empty paths or `.` - let entry = head.get_path(path.as_std_path())?; + let Some(entry) = head.get_path(path.as_std_path()).ok() else { + return Ok(None); + }; if entry.filemode() == i32::from(git2::FileMode::Link) { - bail!( - "symlink has no - committed text" - ); + return Ok(None); } let content = repo.find_blob(entry.id())?.content().to_owned(); Ok(String::from_utf8(content).ok())