Fix blank git diff view on Windows when working in a subfolder (#52234)

## Context

Fixes a Windows path handling bug in `crates/util/src/paths.rs` when
computing a relative path via `strip_prefix`. (Closes #51758 )

Previously, Windows prefix matching only handled drive-letter
case-insensitivity. It could still fail when the parent and child paths
referred to the same location but used different separator styles (`\`
vs `/`) or different casing in later path segments. That caused valid
Windows paths to return `None` instead of a relative path, which caused
the diff to break.

This change normalizes Windows paths for prefix comparison by
lowercasing any ASCII characters and converting backslashes to forward
slashes before checking the prefix.

Tests were added for mixed-case and mixed-separator Windows paths to
cover the bug and prevent further regressions.

## How to Review

1. Check the `strip_prefix` Windows branch to confirm the new
normalization logic only affects prefix comparison and still rejects
partial-segment matches.
2. Check the added tests for mixed separator and mixed casing cases on
Windows paths.

## Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fix blank git diff view on Windows when working in a subfolder

---------

Co-authored-by: John Tur <john-tur@outlook.com>
This commit is contained in:
Hitesh Rohira 2026-04-22 03:54:49 +05:30 committed by GitHub
parent 2542b71a24
commit f8295ffaca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4024,10 +4024,12 @@ impl RepositorySnapshot {
}
fn repo_path_to_abs_path(&self, repo_path: &RepoPath) -> PathBuf {
self.path_style
.join(&self.work_directory_abs_path, repo_path.as_std_path())
.unwrap()
.into()
let repo_path = repo_path.display(self.path_style);
PathBuf::from(
self.path_style
.join(&self.work_directory_abs_path, repo_path.as_ref())
.unwrap(),
)
}
#[inline]