Skip to content

fix(path): normalize Windows UNC paths for WSL2 repo access#19

Draft
noahbclarkson wants to merge 2 commits intomainfrom
fix/wsl2-unc-path
Draft

fix(path): normalize Windows UNC paths for WSL2 repo access#19
noahbclarkson wants to merge 2 commits intomainfrom
fix/wsl2-unc-path

Conversation

@noahbclarkson
Copy link
Copy Markdown
Owner

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\path form is rejected; the equivalent //server/share/path (forward slashes) is accepted.

Fix

Added normalize_repo_path(PathBuf) -> PathBuf in rgitui_git:

  • On Windows: if the path starts with \\\\ (backslash UNC prefix), every backslash is converted to a forward slash.
  • On Linux/macOS: function is a no-op (no runtime overhead).

Applied in two places:

  1. GitProject::open — normalises before git2::Repository::open
  2. Workspace::open_repo (tabs.rs) — normalises before the path.exists() guard and the early git2::Repository::open validation

Tests

Unit tests in rgitui_git::project::tests:

  • normalize_non_unc_path_unchanged — Linux/macOS paths pass through
  • normalize_relative_path_unchanged — relative paths unaffected
  • Windows-only (cfg(windows)):
    • normalize_wsl_localhost_unc_path\\wsl.localhost\distro\home\user\repo//wsl.localhost/distro/home/user/repo
    • normalize_wsl_dollar_unc_path — old \\wsl$\\ form
    • normalize_windows_drive_path_unchangedC:\\Users\\.... unchanged
    • normalize_network_share_unc_path — generic UNC share normalised

Forge and others added 2 commits April 20, 2026 07:08
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cannot open git repositories from WSL2

1 participant