Remove git diff base from symlinked files (#10037)
Closes https://github.com/zed-industries/zed/issues/4730  To the left is a symlink, to the right — the real file. The issue was due to the fact, that symlinks files contain the file path to the real file, and git (properly) treats that symlink file contents as diff base, returning in `load_index_text` (via `let content = repo.find_blob(oid)?.content().to_owned();`) the contents of that symlink file — the path. The fix checks for FS metadata before fetching the git diff base, and skips it entirely for symlinks: Zed opens the symlink file contents instead, fully obscuring the git symlink diff hunks. Interesting, that VSCode behaves as Zed before the fix; while the fix makes Zed behave like Intellij* IDEs now. Release Notes: - Fixed git diff hunks appearing in the symlinked files ([4730](https://github.com/zed-industries/zed/issues/4730))
This commit is contained in:
@@ -1081,10 +1081,25 @@ impl LocalWorktree {
|
||||
{
|
||||
if let Some(git_repo) = snapshot.git_repositories.get(&*repo.work_directory) {
|
||||
let git_repo = git_repo.repo_ptr.clone();
|
||||
index_task = Some(
|
||||
cx.background_executor()
|
||||
.spawn(async move { git_repo.lock().load_index_text(&repo_path) }),
|
||||
);
|
||||
index_task = Some(cx.background_executor().spawn({
|
||||
let fs = fs.clone();
|
||||
let abs_path = abs_path.clone();
|
||||
async move {
|
||||
let abs_path_metadata = fs
|
||||
.metadata(&abs_path)
|
||||
.await
|
||||
.with_context(|| {
|
||||
format!("loading file and FS metadata for {abs_path:?}")
|
||||
})
|
||||
.log_err()
|
||||
.flatten()?;
|
||||
if abs_path_metadata.is_dir || abs_path_metadata.is_symlink {
|
||||
None
|
||||
} else {
|
||||
git_repo.lock().load_index_text(&repo_path)
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user