fix(path): normalize Windows UNC paths for WSL2 repo access#19
Draft
noahbclarkson wants to merge 2 commits intomainfrom
Draft
fix(path): normalize Windows UNC paths for WSL2 repo access#19noahbclarkson wants to merge 2 commits intomainfrom
noahbclarkson wants to merge 2 commits intomainfrom
Conversation
libgit2 on Windows rejects UNC paths that use backslashes (e.g. \wsl.localhost\distro\home\user\repo). Converting the leading '\\' prefix and all backslashes to forward slashes produces a path libgit2 accepts: //wsl.localhost/distro/... Changes: - Add normalize_repo_path() in rgitui_git::project — exported as pub so callers outside the crate can use it - Apply normalization in GitProject::open before git2 open call - Apply normalization in Workspace::open_repo before exists() check and git2::Repository::open validation - Add unit tests for normalize_repo_path (non-UNC pass-through tested on all platforms; UNC conversion gated on cfg(windows)) Fixes #18
The previous guard rewrote any path starting with \, which also captured extended-length (\?\) and device-namespace (\.\) prefixes. std::fs::canonicalize returns \?\ paths, and libgit2 does not accept their slash-converted form. Narrow the guard so only share-style UNC paths (\server\share, \wsl.localhost) are rewritten, and add tests covering both excluded prefixes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #18.
On Windows, users opening a repository via the WSL2 virtual filesystem (e.g.
\\wsl.localhost\archlinux\home\user\repo) hit an error toast and cannot open the repo.Root cause: libgit2 on Windows does not accept UNC paths that use backslashes. The
\\server\share\pathform is rejected; the equivalent//server/share/path(forward slashes) is accepted.Fix
Added
normalize_repo_path(PathBuf) -> PathBufinrgitui_git:\\\\(backslash UNC prefix), every backslash is converted to a forward slash.Applied in two places:
GitProject::open— normalises beforegit2::Repository::openWorkspace::open_repo(tabs.rs) — normalises before thepath.exists()guard and the earlygit2::Repository::openvalidationTests
Unit tests in
rgitui_git::project::tests:normalize_non_unc_path_unchanged— Linux/macOS paths pass throughnormalize_relative_path_unchanged— relative paths unaffectedcfg(windows)):normalize_wsl_localhost_unc_path—\\wsl.localhost\distro\home\user\repo→//wsl.localhost/distro/home/user/reponormalize_wsl_dollar_unc_path— old\\wsl$\\formnormalize_windows_drive_path_unchanged—C:\\Users\\....unchangednormalize_network_share_unc_path— generic UNC share normalised