wslgit icon indicating copy to clipboard operation
wslgit copied to clipboard

Cannot handle path when working from WSL path in Windows

Open alecxvs opened this issue 5 years ago • 12 comments

The insider build for 1903 has a new functionality that allows browsing files on WSL from explorer. The paths look like \\wsl$\Ubuntu\home\alecxvs\Git\myproject.

Running wslgit from this path gives this error: thread 'main' panicked at 'Cannot handle path "\\\\wsl$\\Ubuntu\\home\\alecxvs\\Git\\myproject"', src\libcore\option.rs:1008:5

alecxvs avatar Apr 28 '19 17:04 alecxvs

Yes, it would be nice to support these new paths. Right now, wslgit assumes that Windows paths start with a drive letter (to translate them into a proper unix path).

Adding support for these paths should be possible, e.g. by detecting and removing the prefix.

andy-5 avatar Apr 29 '19 08:04 andy-5

+1

roonie007 avatar May 28 '19 15:05 roonie007

Adding support for these paths should be possible, e.g. by detecting and removing the prefix.

@andy-5 why don't you use wslpath for things like that? E.g. wsl.exe wslpath -u "\\\\wsl$\\Ubuntu\\home\\alecxvs\\Git\\myproject" would return /home/alecxvs/Git/myproject. Would it make your life easier? :)

chadrien avatar Aug 15 '19 06:08 chadrien

Thanks for the suggestion (and good to know that it supports these paths). There is already some discussion on wslpath in #12. Unfortunately, it does not solve all problems. The main reasons it is not used are:

  • it does not fully support manually mounted drives
  • executing a separate process is slow
  • nobody has done the work to implement support for it

andy-5 avatar Aug 19 '19 08:08 andy-5

It should be super simple to convert WSL2 UNC paths: just add/remove the \\wsl$\Distroname and flip the backslashes. No need to resolve mount paths in that case. However, I'm not sure if there's some special consideration needed for running executables when the current directory is a UNC path. At least .bat scripts have problems with those.

Ideally, this would detect the UNC paths and also work with DrvFs or 9p mounts, so it'd work whether the git repo resides on the Windows side or the Linux side.

rennex avatar Oct 02 '19 13:10 rennex

I just released v0.9.0, which uses wslpath to translate paths (and should handle UNC paths). Does the new version resolve this issue?

andy-5 avatar Jan 10 '20 07:01 andy-5

Not quite, I have a repo at

\\wsl$\Ubuntu\home\stan\projects\personal\WeakAuras2

and when I go to it via CMD (which is T:\home\stan\projects\personal\WeakAuras2) and type git status it does not detect it as a git repo. When I then type git init, it inits in my WSL user folder,

PS T:\home\stan\projects\personal\WeakAuras2> git init
Initialized empty Git repository in \wsl$\Ubuntu\home\stan\.git

Stanzilla avatar Feb 07 '20 11:02 Stanzilla

@carlolars any idea for this maybe?

Stanzilla avatar Apr 03 '20 10:04 Stanzilla

@carlolars any idea for this maybe?

To access mapped network drives they must be manually mounted inside WSL. wslpath cannot figure out that T: in your case is actually is \\wsl$\Ubuntu since it only gets the windows path (T:\home\stan...). So you have to mount the network drive inside WSL and then wslpath will know how to translate a path that begins with T: to the mounted path.

But unfortunately it seems to not be possible to, in WSL, mount a network drive that points to the WSL filesystem. I even tried to do a bind mount of the root filesystem to my /mnt/t but it didn't work.

I see that you actually use Power Shell and not cmd.exe. In PS you can actually do cd \\wsl$\Ubuntu\home\stan\projects\personal\WeakAuras2 😄

carlolars avatar Apr 03 '20 18:04 carlolars

but T IS the WSL mount, how would I mount it inside of WSL?

Stanzilla avatar Apr 03 '20 18:04 Stanzilla

but T IS the WSL mount, how would I mount it inside of WSL?

You can't.

carlolars avatar Apr 03 '20 19:04 carlolars

Yeah well for this cmd/ps example it does not really matter but I was mainly testing this way because it did not work in Fork either.

Stanzilla avatar Apr 03 '20 19:04 Stanzilla