diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index 9b17ed20b4..b29d4b226d 100644 --- a/crates/git/src/repository.rs +++ b/crates/git/src/repository.rs @@ -84,12 +84,12 @@ pub trait GitRepository: Send + Sync { /// Returns the contents of an entry in the repository's index, or None if there is no entry for the given path. /// - /// Note that for symlink entries, this will return the contents of the symlink, not the target. + /// Also returns `None` for symlinks. fn load_index_text(&self, path: &RepoPath) -> Option; /// Returns the contents of an entry in the repository's HEAD, or None if HEAD does not exist or has no entry for the given path. /// - /// Note that for symlink entries, this will return the contents of the symlink, not the target. + /// Also returns `None` for symlinks. fn load_committed_text(&self, path: &RepoPath) -> Option; fn set_index_text(&self, path: &RepoPath, content: Option) -> anyhow::Result<()>; @@ -286,8 +286,11 @@ impl GitRepository for RealGitRepository { fn load_committed_text(&self, path: &RepoPath) -> Option { let repo = self.repository.lock(); let head = repo.head().ok()?.peel_to_tree().log_err()?; - let oid = head.get_path(path).ok()?.id(); - let content = repo.find_blob(oid).log_err()?.content().to_owned(); + let entry = head.get_path(path).ok()?; + if entry.filemode() == i32::from(git2::FileMode::Link) { + return None; + } + let content = repo.find_blob(entry.id()).log_err()?.content().to_owned(); let content = String::from_utf8(content).log_err()?; Some(content) }