Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execute git in WSL for WSL paths #532

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

schummar
Copy link

@schummar schummar commented Mar 21, 2023

Motivation

Executing git commands from Windows on WSL (Windows Subsystem for Linux) paths has some problems. The major ones (that I'm aware of) are

  • The performance is bad because cross file system file access is slooow
  • By default just checking out a branch will create changes from the WSL point of view because file endings are "wrong". I know line ending behavior can be configured, but out-of-the box this creates chaos.
  • Git hooks don't work

My use case is, I would like to use GitHub Desktop to manage my git repos both in windows and in WSL, where I do most of my programming. Commonly recommended solutions like running GitHub Desktop in WSL (WSL GUIs are not stable enough for my tastes) or just opening the WSL path in GitHub Desktop on Windows (suffers from the above mentioned issues) are not working for me.

There are a number of issues that are related to this, e.g. desktop/desktop#13953

Solution

So my suggestion is this: When working in repositories that have a WSL path (e.g. \\wsl$\home\user\src\whatever or \\wsl.localhost\\Ubuntu\home\user\src\whatever), execute git commands within WSL: wsl.exe -e git .... This PR is a POC and probably needs more work, so I am grateful for any feedback. It works very smoothly in my locally built GitHub Desktop though.

My considerations so far:

Performance

The approach works a lot faster on my machine. I can't say I have done bullet proof benchmarking yet, but some of my tests show significant improvements:

Opening a repository - old:

Executing getBranches: git for-each-ref --format=%00%(refname)%00%(refname:short)%00%(upstream:short)%00%(objectname)%00%(author)%00%(symref)%00 refs/heads refs/remotes (took 1.495s)
Executing getCommits: git log HEAD --date=raw --max-count=100 -z --format=%H%x00%h%x00%s%x00%b%x00%an <%ae> %ad%x00%cn <%ce> %cd%x00%P%x00%(trailers:unfold,only)%x00%D --no-show-signature --no-color --not --remotes -- (took 2.632s)
Executing getAllTags: git show-ref --tags -d (took 1.890s)

Opening a repository - new:

Executing getBranches: git for-each-ref --format=%00%(refname)%00%(refname:short)%00%(upstream:short)%00%(objectname)%00%(author)%00%(symref)%00 refs/heads refs/remotes (took 0.155s)
Executing getCommits: git log HEAD --date=raw --max-count=100 -z --format=%H%x00%h%x00%s%x00%b%x00%an <%ae> %ad%x00%cn <%ce> %cd%x00%P%x00%(trailers:unfold,only)%x00%D --no-show-signature --no-color --not --remotes -- (took 0.203s)
Executing getAllTags: git show-ref --tags -d (took 0.140s)

Checking out a branch - old:

Executing checkoutBranch: git -c credential.helper= checkout --progress master --recurse-submodules -- (took 1.679s)
[Timing] Action 'checkout branch from list' for 'schummar/schummar-state' took 3.284s

Checking out a branch - new:

Executing checkoutBranch: git -c credential.helper= checkout --progress master --recurse-submodules -- (took 0.133s)
[Timing] Action 'checkout branch from list' for 'schummar/schummar-state' took 1.094s

Authentication

WSL has a neat mechanism to forward environment variables between WSL and Windows processes. It even can convert paths while doing it. By forwarding certain env vars, authentication seem to work nicely for private repositories.

Multiple WSL distributions

Since the distribution name is part of the WLS repo path, it can be specified in the command, so working across multiple distributions should work, though I didn't test that case yet.

@refringe
Copy link

@schummar Thank you for looking into this. I would love for this feature to get merged.

@SynthLuvr
Copy link

Thanks for putting this together. I tried to get this working with my local GitHub Desktop but was unsuccessful. The error I'm seeing is "Git could not be found at the expected path"

@schummar
Copy link
Author

You need to use the modified GitHub Desktop version from this PR: desktop/desktop#16378

@schummar
Copy link
Author

schummar commented Apr 26, 2023

A little script for anyone who wants to try it out:

git clone https://github.com/schummar/dugite.git
git clone https://github.com/schummar/desktop.git

cd dugite
git checkout origin/feature/wslGit
yarn
yarn build
yarn link

cd ../desktop
git checkout origin/feature/wslCompatibility
yarn
cd app
yarn link dugite
cd ..
yarn build:prod

@SynthLuvr
Copy link

Thanks @schummar, that helps a lot. I'm still getting errors when running GitHub Desktop though:

  • error launching git: The system cannot find the path specified.
  • Failed to execute getStatus: ENOENT
  • Git returned an unexpected exit code '1' which should be handled by the caller (getStatus).'

It also fails to load any repository from WSL, keeps show "Can't find [repo]"

@schummar
Copy link
Author

schummar commented Apr 26, 2023

Ah my bad. I forgot that you have to link dugite in the app folder as well. I have updated the script.

Edit: Actually, only in the app folder. Root was just plain wrong 😬

@SynthLuvr
Copy link

It's working for me, thanks!

@CaseyLabs
Copy link

Bumping this PR! WSL-based git would be fantastic.

@SynthLuvr
Copy link

I've been running this since April. I'm too afraid to update to the latest version in case I can't get this feature working again. So I'm sticking with this PR and forgoing updates.

@schummar
Copy link
Author

I've updated the branches once again. You can create a current build if you want. 😉

@Stanzilla
Copy link

@sergiou87 any chance this can be looked at? cheers

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.

5 participants