From 76f501af713d51a329b54a389c54ebf39bfc4bf9 Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Tue, 18 Feb 2025 10:18:23 -0500 Subject: [PATCH] git: Don't load shallow HEAD text of symlinks (#25058) For symlinks, return `None` from `load_committed_text` as we do from `load_index_text` ever since #10037. Release Notes: - Fixed diff hunks appearing in unchanged symlinked files --- crates/git/src/repository.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index 9b17ed20b44664c7398446fd86dfbc5a4a9b6315..b29d4b226d059f5f4f18299e17844fa9f921a254 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) }