Skip to content

fix(git): run git inside the distro for folders on a WSL share - #451

Merged
amirlehmam merged 1 commit into
amirlehmam:masterfrom
stlindenau:fix/git-in-wsl-for-unc-folders
Nov 13, 2026
Merged

amirlehmam merged 1 commit into
amirlehmam:masterfrom
stlindenau:fix/git-in-wsl-for-unc-folders

Conversation

@stlindenau

@stlindenau stlindenau commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

For a pane whose cwd is \\wsl.localhost\<distro>\…, wmux runs the Windows git.exe against the share. That goes wrong in two ways:

  • Ownership. Files on the share never belong to the Windows account, so git refuses the repo with fatal: detected dubious ownership. diff-provider.ts reads any failed git rev-parse as "not a repository" and falls back to the snapshot backend, which ignores .gitignore (an ignored mlruns/ full of .json showed up as changes). The Git view shows the raw error.
  • Modes and symlinks. With core.filemode=true, Windows git sees every executable file and every symlink as modified.

safe.directory and core.filemode/core.symlinks flags don't cleanly fix this: trusting a repo makes Windows git run its config (core.fsmonitor, diff drivers, …) on the host, and core.symlinks=false makes git compare a link's target text with the file it finds, so symlinks still show as modified.

Change

gitCommand(cwd, args) in git-view.ts decides how to run git for a folder:

  • WSL share (\\wsl.localhost\…, \\wsl$\…, either slash spelling): System32\wsl.exe -d <distro> --cd <posix path> --exec git …. Linux git sees the real modes and symlinks and owns the repo, so no flags and no trust decision are needed, and a hostile repo config runs inside WSL, not on Windows. --exec means no shell re-parses the arguments, and wsl.exe is the absolute System32 one, for the same reason gitExecutable() is absolute.
  • Everything else: the absolute Windows git, unchanged.

Details:

  • Paths git prints (rev-parse --show-toplevel, worktree list) are POSIX; they are translated back to \\wsl.localhost\<distro>\… (or C:\… for /mnt/c) before being used as the next cwd (fromGitPath).
  • GIT_OPTIONAL_LOCKS / GIT_TERMINAL_PROMPT are forwarded into WSL through WSLENV.
  • Used by both git runners that matter here: git() in git-view.ts and git() in diff-provider.ts.
  • diff-provider.ts is CRLF in this repo and stays CRLF (2-line diff); the other files are LF.

Not changed

  • git-worktree.ts (managed worktree create/remove) still uses Windows git. Those commands take Windows paths, so they need their own treatment.
  • No change to how the explorer's root is resolved.

Cost

Each git call for a WSL folder now pays a wsl.exe start. I haven't measured it. diff-provider already coalesces concurrent calls and TTL-caches the repo probe, but the diff poll will spawn wsl.exe where it used to spawn git.exe.

Testing

  • Unit tests for the UNC parser (both slash spellings, lookalikes rejected), the POSIX→Windows path mapping, the command built for a WSL folder and for a drive folder, and WSLENV forwarding. git-view, diff-provider-git and git-worktree* suites pass (84 passed, 1 skipped); tsc and eslint are clean.
  • Checked by hand on Windows + WSL2 (Ubuntu 24.04), with a repo on the WSL filesystem: the diff view and the Git view show no spurious changes. I did not test several distros, a distro that is not running, or a distro without git on its default PATH.
  • The unit tests do not run wsl.exe.

🤖 Generated with Claude Code

Windows git over \\wsl.localhost\<distro>\... gets the executable bit, symlinks
and ownership wrong: every executable file and symlink reads as modified, and
git refuses the repository ('dubious ownership'), so diff-provider treats the
folder as not a repository and falls back to the snapshot backend, which
ignores .gitignore.

Run git as 'wsl.exe -d <distro> --cd <path> --exec git' for those folders
instead. Linux git sees the real modes and symlinks and owns the repository, so
no config flags or safe.directory are needed, and a hostile repo config runs
inside WSL rather than on Windows. POSIX paths git prints (toplevel, worktree
list) are translated back to Windows paths. Other folders keep the absolute
Windows git. Managed worktrees (git-worktree.ts) are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@amirlehmam
amirlehmam merged commit 0da2a35 into amirlehmam:master Nov 13, 2026
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.

2 participants