fix(git): route git operations through wsl.exe for WSL UNC paths#314
fix(git): route git operations through wsl.exe for WSL UNC paths#314withabdul wants to merge 2 commits into
Conversation
When a project points at a WSL folder via UNC path (e.g. \\wsl.localhost\Ubuntu-24\home\user\project), the branch indicator in the status bar worked but the Git Changes sidebar panel showed zero changes. Root cause: 'git status --porcelain' against a 9P UNC share either times out (2s default) or returns empty output, so git_get_status_detail returns an IPC error. The renderer's refreshStatus does not toast on error, so the failure is silent. Fix: detect WSL UNC paths and spawn git via 'wsl.exe -d <distro> --exec git -C <linux-path>' with wslpath -u translation (cached). Non-WSL paths unchanged. 8s timeout on WSL for cold-start tolerance. Adds 11 unit tests for WSL path detection (case-insensitive, both UNC forms, distro case preservation, native/Unix rejection).
|
Complex PR? Review this PR in Change Stack to move by importance, not file order. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds Windows handling for WSL UNC paths: detects/extracts distro names, caches wslpath -u translations, picks WSL-specific git timeouts, and routes git commands through wsl.exe (returning None on translation failure). Includes unit tests for UNC detection and extraction. ChangesWSL Git Command Execution on Windows
Sequence Diagram(s)sequenceDiagram
participant Caller
participant PathDetector
participant PathTranslator
participant TimeoutPicker
participant WslExecution
Caller->>PathDetector: request git operation with Windows path
PathDetector->>PathDetector: is_wsl_path / extract_wsl_distro
alt WSL path detected
PathDetector->>PathTranslator: translate via wslpath -u (cached)
alt Translation succeeds
PathTranslator-->>PathDetector: Linux path
PathDetector->>TimeoutPicker: pick_git_timeout_ms
TimeoutPicker-->>PathDetector: effective timeout
PathDetector->>WslExecution: wsl.exe -d <distro> --exec git -C <linux_path>
WslExecution-->>Caller: command result
else Translation fails
PathTranslator-->>PathDetector: None
PathDetector-->>Caller: None (log warning)
end
else Non-WSL path
PathDetector->>TimeoutPicker: pick_git_timeout_ms
TimeoutPicker-->>PathDetector: effective timeout
PathDetector->>WslExecution: spawn Windows git with effective timeout
WslExecution-->>Caller: command result
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src-tauri/src/trackers/git_tracker.rs (1)
236-242: 💤 Low valueComment example is misleading.
The comment says it rejects
\\wsl$\foo, but that path would havedistro="foo"which is not empty. The code actually rejects\\wsl$\(prefix with no distro segment). Consider updating the example:- // Distro name extends to the next path separator. Reject empty distro - // (`\\wsl$\foo`) and slices beyond the prefix. + // Distro name extends to the next path separator. Reject empty distro + // segment (e.g. `\\wsl$\` with nothing after the prefix).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src-tauri/src/trackers/git_tracker.rs` around lines 236 - 242, Update the misleading comment above the logic that extracts the distro (variables end, after, distro): it currently claims it rejects `\\wsl$\foo` but the code would accept that and actually rejects an empty distro like `\\wsl$\` (no segment after the prefix); change the example in the comment to `\\wsl$\` (or similar showing a trailing separator with no distro) and adjust wording to state it rejects an empty distro segment rather than `\\wsl$\foo`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src-tauri/src/trackers/git_tracker.rs`:
- Around line 827-848: The GIT_TERMINAL_PROMPT env currently set on the wsl.exe
process won't be passed into the Linux git; change the constructed command so
the env is set inside WSL by invoking env before git (e.g., use
backend_command("wsl.exe") with .args([... "--exec", "env",
"GIT_TERMINAL_PROMPT=0", "git", "-C", &linux_path]) instead of
.env("GIT_TERMINAL_PROMPT","0"); update the block that builds the command in the
WSL branch (where extract_wsl_distro, wslpath_translate, backend_command and
Self::spawn_and_wait are used) so the env assignment is part of the --exec
arguments.
---
Nitpick comments:
In `@src-tauri/src/trackers/git_tracker.rs`:
- Around line 236-242: Update the misleading comment above the logic that
extracts the distro (variables end, after, distro): it currently claims it
rejects `\\wsl$\foo` but the code would accept that and actually rejects an
empty distro like `\\wsl$\` (no segment after the prefix); change the example in
the comment to `\\wsl$\` (or similar showing a trailing separator with no
distro) and adjust wording to state it rejects an empty distro segment rather
than `\\wsl$\foo`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4d413980-2f38-4428-98df-0b4f4fb88318
📒 Files selected for processing (1)
src-tauri/src/trackers/git_tracker.rs
The previous patch set GIT_TERMINAL_PROMPT=0 on the wsl.exe Windows process via .env(), but wsl.exe only forwards a small set of well-known env vars to the Linux side; arbitrary ones (including GIT_TERMINAL_PROMPT) never reach git running inside the WSL distro. As a result, git push on a WSL project could still block on a credentials prompt at the 2s default timeout instead of failing fast. Move the env assignment into the --exec invocation so it is set on the Linux side: 'wsl.exe --exec env GIT_TERMINAL_PROMPT=0 git ...'. The non-WSL Windows branch is unchanged — .env() on a Windows process is the correct way to set env for a Windows child.
|
Hey @withabdul — triage update 🔁 Mergeable, but CI is red: Rust Checks (fails The branch appears out of sync with |
Summary
Routes git operations through
wsl.exewhen a project's CWD is a WSL UNC path (e.g.\\wsl.localhost\Ubuntu-24\home\user\project). Fixes the Git Changes sidebar panel showing zero entries on WSL projects, while leaving the branch indicator working.Related Issue
None — discovered while using Termul on a Windows host with a project inside WSL.
Type of Change
What Changed
Problem:
git rev-parse --abbrev-ref HEADsucceeds against a 9P UNC path (cheap metadata read), so the status bar shows the correct branch.git status --porcelaintraverses the working tree and either times out at the 2sGIT_COMMAND_TIMEOUT_MSor returns empty, sogit_get_status_detailreturns an IPC error. The renderer'srefreshStatusingit-status-store.tshas notry/catchtoast, so the failure is silent and the sidebar shows "No changes detected".Fix: Detect WSL UNC paths in
git_tracker.rsand spawngitinside the WSL distro viawsl.exe -d <distro> --exec git -C <linux-path> <args>. Path translation useswsl.exe -d <distro> --exec wslpath -u <windows-path>, cached per session in aOnceLock<Mutex<HashMap>>to amortise the WSL service cold-start cost. Effective timeout bumped to 8s on WSL paths. Non-WSL paths are unchanged — fast path-string check, falls through to existing Windows git.New helpers (all
#[cfg(target_os = "windows")]):is_wsl_path/extract_wsl_distro— recognise\\wsl$\<distro>\and\\wsl.localhost\<distro>\, case-insensitive prefix, distro case preserved.wslpath_translate—wslpath -uwith caching.pick_git_timeout_ms— 8s on WSL, requested on native.run_git_command_with_timeoutandrun_git_pushroute throughwsl.exeon WSL paths. WSL detected butwslpathfails → returnNone(no silent fallback to Windows git).How It Was Tested
bun run lint(frontend; no changes)bun run typecheck(frontend; no changes)bun run test— Rust tests gated by#[cfg(target_os = "windows")]; cannot run in the development sandbox (target not installed). Should be run on a Windows host:cd src-tauri && cargo test --target x86_64-pc-windows-msvc.Manual verification steps:
\\wsl.localhost\<distro>\home\<user>\<project>.git statusinside the WSL shell shows changes.Screenshots or Recordings
Not applicable — UI behaviour change is the appearance of the existing (currently empty) Git Changes list. No new UI surfaces.
Checklist
fix(git): ...)src-tauri/src/trackers/git_tracker.rs)Summary by CodeRabbit
Bug Fixes
Tests