Skip to content

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

Merged
reflectronic merged 3 commits intozed-industries:mainfrom
HiteshRohira:fix-git-diff-for-subfolder
Apr 21, 2026
Merged

Fix blank git diff view on Windows when working in a subfolder#52234
reflectronic merged 3 commits intozed-industries:mainfrom
HiteshRohira:fix-git-diff-for-subfolder

Conversation

@HiteshRohira
Copy link
Copy Markdown
Contributor

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

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Fix blank git diff view on Windows when working in a subfolder
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Mar 23, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator Bot requested review from a team, cole-miller and kubkon and removed request for a team March 23, 2026 17:46
@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Mar 23, 2026
@cole-miller
Copy link
Copy Markdown
Member

Thanks @HiteshRohira!

This change makes sense in the abstract, but I'd like to understand how it fixes the issue you're seeing. Are you seeing that we're not successfully doing abs_path_to_repo_path on Windows in the case of a repository root above the worktree root? If so, what do the paths involved look like? I'm curious because it seems like in that codepath the repository root is ultimately constructed from one of the Path::ancestors of the worktree root, so I'm not sure how they end up with different casing or separators.

Also cc @reflectronic who is more knowledgeable about Windows paths than I am.

Comment thread crates/util/src/paths.rs Outdated
@HiteshRohira HiteshRohira force-pushed the fix-git-diff-for-subfolder branch from 1b799b1 to 3a5dc8e Compare April 6, 2026 22:39
@HiteshRohira HiteshRohira reopened this Apr 6, 2026
@HiteshRohira
Copy link
Copy Markdown
Contributor Author

This is what the differences in paths were looking like. This comes from logs in the strip_prefix function

child="C:\\Users\\hites\\code\\Test\\Test2/Testaa3/Test4/Testing5/Test6/whytho.md" parent="C:\\Users\\hites\\code\\Test\\Test2\\Testaa3\\Test4"
child="C:\\Users\\hites\\code\\Test\\Test2/Testaa3/Test4/Testing5/test2.md" parent="C:\\Users\\hites\\code\\Test\\Test2\\Testaa3\\Test4"
child="C:\\Users\\hites\\code\\Test\\Test2/Testaa3/Test4/test.md" parent="C:\\Users\\hites\\code\\Test\\Test2\\Testaa3\\Test4"

@cole-miller thank you for the pushback on this, the bug ended up being in a different place. When zed was joining paths in repo_path_to_abs_path it produced mixed paths like

C:\Users\hites\code\Test\Test2/Testaa3/Test4/test.md

When that path went into find_worktree and from there into strip_prefix it failed because it was receiving something like this

child  = C:\Users\hites\code\Test\Test2/Testaa3/Test4/test.md
parent = C:\Users\hites\code\Test\Test2\Testaa3\Test4

I have fixed repo_path_to_abs_path such that it first converts the repo path

@devoper2022
Copy link
Copy Markdown

can we know the status of this PR

@HiteshRohira
Copy link
Copy Markdown
Contributor Author

@devoper2022 just waiting for approval

@devoper2022
Copy link
Copy Markdown

@Anthony-Eid can you review this PR

@reflectronic reflectronic self-requested a review April 20, 2026 16:27
Copy link
Copy Markdown
Member

@reflectronic reflectronic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@reflectronic reflectronic merged commit f8295ff into zed-industries:main Apr 21, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

6 participants