microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.61k stars 29.03k forks source link

Git: Support WSL #9502

Closed tianvan closed 5 years ago

tianvan commented 8 years ago

qq 20160720033734

joaomoreno commented 8 years ago

This was fast. The thing literally came out yesterday for everyone.

Actually, it's still not yet out, so support for this will take its time.

johnbwoodruff commented 8 years ago

It would be great to use Bash on Ubuntu on Windows as the integrated terminal! Not to mention its git installation for the git tab. I can't +1 this enough! :)

johnbwoodruff commented 8 years ago

Noticed that we can use the Bash on Ubuntu on Windows terminal in the integrated terminal now. That's awesome! Now we just need the git integration with the git version installed through bash on ubuntu on windows.

dalyIsaac commented 8 years ago

+1

ncarroll commented 8 years ago

+1

nmbradford commented 8 years ago

+1

jonomacd commented 7 years ago

This would be great not just for git but for extensions as well. I use the vscode-go extension and it shells out to use the command line tools often. I'd like it if it could shell out to bash as opposed to windows terminal. It would also need access to environment variables from bash. Basically, I want it to think it is in a bash environment even though it is in windows.

Thanks.

ElieMyIdea commented 7 years ago

+1

andre2 commented 7 years ago

+1

doxiaodong commented 7 years ago

+1

lobabob commented 7 years ago

+1

emmanuelvlad commented 7 years ago

+1

kidpollo commented 6 years ago

+1

mikaelbalin commented 6 years ago

+1

lugolven commented 6 years ago

+1 :)

sgiradoa-psl commented 6 years ago

+1

skippednote commented 6 years ago

@joaomoreno Wanted to check if there any work being done on this WSL git + VSCode integration?

nickjj commented 6 years ago

With Insider's 1.19 from Nov 15th I was able to track git commits with having VSCode installed on Windows while having git installed on WSL and do basically everything except pull/push (due to VSCode not using SSH keys from WSL) without any configuration or hacks.

But, with today's Nov 20th update now it's complaining about the git.path not finding a suitable version of git. However, it only checks Windows for a git installation instead of WSL.

Since this feature was working a few days ago, what should the new git.path be set to in order to integrate with WSL's git? i tried all sorts of bash.exe related paths without success.

CoenraadS commented 6 years ago

@nickjj Just set it to your Windows git.exe. VSCode never had support for WSL git. You can still use most of the features, but it will use the windows config not the WSL config.

nickjj commented 6 years ago

@CoenraadS I never had Git installed on Windows (ever).

Prior to this patch, the editor was capable of showing changes in a repo when git was only installed on WSL.

Is there a way I can roll back to Nov 15th's release?

CoenraadS commented 6 years ago

Prior to the latest insiders it checked the PATH, so if you do cmd -> where git.exe you might be surprised.

nickjj commented 6 years ago

where git.exe returns nothing from PowerShell, because I don't have Git installed on Windows.

If I run which git from WSL it's found at /usr/bin/git.

CoenraadS commented 6 years ago

I discovered this great project: https://github.com/andy-5/wslgit for people who want this support today.

ping @joaomoreno because maybe this would be an interesting route for VSCode team to think about.

refparo commented 6 years ago

+1

erend commented 6 years ago

+1 Integrating this feature make web coding on Windows perfect.

OmriSama commented 6 years ago

+1

seashore001x commented 6 years ago

+1

johnbwoodruff commented 6 years ago

Hey everyone, friendly reminder to use the thumbs up reaction to the original comment instead of everyone posting +1. :) That's how interest is gauged, not by the number of comments with +1 which is harder to quantify. (Also doesn't spam everyone's notifications) ;)

nikhilweee commented 6 years ago

So with the new year, is there a native solution yet? Or is wslgit still the best workaround for now?

mikerockett commented 6 years ago

Looks like this hasn’t made it to the roadmap. :cry:

trickymast3r commented 6 years ago

Im workin in this !

erikmueller commented 6 years ago

Just a naïve approach: I tried installing Git for windows, then added the Program Files/Git/bin to my path and created an alias for git.exe=git (or you alias the exe directly) Since WSL can run windows binaries both (wsl.exe/zsh and vscode integrated terminal) now use the windows git installation. Maybe this helps and sorry if I got the problem wrong ^^

pd93 commented 6 years ago

@erikmueller I believe this issue is for people who are using the WSL as their development environment and don't want to have to install Git for Windows in addition to WSL Git.

In other words, VSCode should be able to use WSL Git as it's SCM rather than requiring users to install additional software (Git for Windows).

It's worth noting that the integrated terminal can already use WSL Git, but that the SCM cannot.

trickymast3r commented 6 years ago

I'm done with this but ... VSCode so hard to commit my code ... sad !

I modify child_process to get into bash.exe and run git ... convert every input path from win style to posix style. convert every result path from posix style to win style. Done ! git still working on my computer ... but i can't commit my work to repo ... i don't know why

pd93 commented 6 years ago

@trickymast3r That's great news. Have you got a fork/PR everyone could take a look at? If you're struggling to submit a PR, take a look at the vscode contribution guide

jednano commented 6 years ago

@trickymast3r I had a similar thing going on in Node.js. I used pkg to package-up my git.js file into a git.exe file that ran a git.cmd file with the following contents:

@echo off
wsl git %*
@echo on

Vscode isn't complaining that Git doesn't exist now, but it is complaining that there are "no active source control providers."

I also tried mklink git.exe git.cmd. No 🎲🎲 !

trusktr commented 6 years ago

Can someone please take this out of Backlog? It's fairly relevant. Especially if you want to entice Linux/macOS devs to use Windows...

Cifram commented 6 years ago

Yes, was just struggling with this and am surprised to find it still not addressed. I'd really not have to maintain my ssh keys in two separate places with two installs of git. VS Code is great about working with WSL in so many ways, but this is still missing.

a-abuelgasim commented 6 years ago

+1

wasabigeek commented 6 years ago

@Cifram I've gotten away with one set of SSH keys by creating one in /mnt/ and using it in both WSL and Windows - maybe that's an option to explore? This doesn't remove the need to install Git on both WSL and Windows though.

MrBlenny commented 6 years ago

I'm doing the same thing. I gave wslgit but it was far too slow to be usable.

Instead installed GIT on windows as well as WSL. Ssh keys are stored in wsl. A symlink/junction was created in windows to link to wsl. Your path will vary.

mklink /J C:\Users\{User}\.ssh C:\Users\{User}\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\{user}\.ssh

I have heard that editing linux files from windows can cause problems so changes to these ssh keys should probably only be made from WSL.

sudesh-poojari commented 6 years ago

+1

patrickxchong commented 6 years ago

+1

iksemot commented 6 years ago

I've been looking into this and, I think, I made a little bit of progress. Maybe someone will be able to take this further.

The way it should work is to set "git.path": "wsl git" in User Settings of VSC as this is the preferred way of running WSL commands [1]. However there seem to be a problem with node child_process when spawning a command with spaces (needs confirmation).

The quite obvious solution, as already suggested [2], is to create a cmd script:

@echo on
wsl git %*
@echo off

and then use it in User Settings; "git.path": "C:\\wsl\\git.cmd".

However there is some problem with that. Turns out that spawning a process which starts wsl, for some reason makes child_process to wait for an input. And that prevents VSC to finish the process of locating git executable.

I monkey-patched resources\app\extensions\git\out\git.js function findSpecificGit to ignore stdin

options = {stdio: ['ignore', null, null]};
const child = cp.spawn(path, ['--version'], options);

And that made VSC to successfully recognize git! But now there's an issue with recognizing git repository.

What VSC does, it goes through various directories, starting with project directory and executes command wsl git rev-parse --show-toplevel which returns an absolute path to the git repository. But it returns it in Unix-lie format. And here I'm stuck.

[1] https://docs.microsoft.com/en-us/windows/wsl/interop#run-linux-tools-from-a-windows-command-line [2] https://github.com/Microsoft/vscode/issues/9502#issuecomment-364043243

pd93 commented 6 years ago

@iksemot Not sure if this is what you're looking for, but since Windows 10 17046 there is a tool called wslpath which will convert between windows/wsl paths. This will be included in the upcoming (April) release of Windows 10 (RS4).

This binary resides in the wsl bin, so perhaps something like this might work? wsl wslpath -wa $(git rev-parse --show-toplevel) That will convert the value returned by git to an absolute windows path.

nikhilweee commented 6 years ago

On the issue of child_process waiting for an input, does https://github.com/nodejs/node/issues/18431 seem to help?

mikaturk commented 6 years ago

So when are we getting a solution which is not a complete hack and just a setting?

Audiosyncrasy commented 6 years ago

👍

kabala commented 6 years ago

👍

victor-perez commented 6 years ago

What you can do is to first try wslpath and if that fails you try a normal git command. It's not ideal but it works.

See: Use WSL git inside VS Code from Windows 10 17046

UPDATED: as @mterrel already noticed the simple version was not able to add/stage files but more important also ls-tree was not working. This is because all of these commands are called with a absolute path. I've updated my version of the git.bat so it can handle calls with absolute paths

There is still one problem what is if you use a passphrase on you ssh for git it will not do any push, pull etc. from VS code. You will get a endless spinner because wsl will show Enter passphrase for /home/user/.ssh/id_rsa but this looks like a general problem of VS code with ssh and passphrase ( https://github.com/Microsoft/vscode/issues/13680 ) This is b.t.w. no problem if you add 'C:\Tools' to your PATH because you can then just enter the passphrase