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

Git can't find %UserProfile%\.gitconfig when running through wslbridge #1654

Open
nickbudi opened this issue Jul 23, 2018 · 10 comments
Open

Comments

@nickbudi
Copy link

nickbudi commented Jul 23, 2018

Versions

ConEmu build: 180626 x64 (portable)
OS version: Windows 10 Pro Build 17134 x64
Used shell version: wslbridge + zsh

Problem description

Git for Windows (installed separately) doesn't find .gitconfig in windows user profile when running git through wslbridge, instead looking for the global gitconfig in %ConEmuBaseDirShort%/home/budi/.gitconfig. But running Git for Windows through wsl.exe + zsh works fine.

Steps to reproduce

  1. Install Git for Windows and add to path (through scoop if that matters)
  2. place .gitconfig in %UserProfile%\.gitconfig
  3. wslbridge task:
set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -cur_console:pnm:/mnt -t zsh
  1. run git.exe config --global --list

Actual results

fatal: unable to read config file 'C:/Program Files/ConEmu/App/ConEmu/ConEmu/home/budi/.gitconfig': No such file or directory

Expected results

user.name=nickbudi
(prints rest of .gitconfig...)
@Maximus5
Copy link
Owner

How does git-for-windows relates to WSL?

@Maximus5
Copy link
Owner

Maximus5 commented Jul 23, 2018

You may (and probably should?) install git via apt.

Anyway, it's a question to wslbridge why only specially defined environment variables are passed to WSL side. You may define them in you task just after --wsl switch like -eUSERPROFILE.

@nickbudi
Copy link
Author

Git for Windows doesn't really relate to WSL, I just would like to use Git for Windows from a WSL shell since native git on WSL has performance issues.

@solesensei
Copy link

@nickbudi have you found any decision yet?

In VSCode i can't using git correctly, because of PATH variable changes at ConEmu startup.

Without opening ConEmu everything works great.

@solesensei
Copy link

@Maximus5 can i use wsl bash without changing PATH like this

set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl

some how

Git for Windows breaks due to these changes.

@zviryatko
Copy link

Hello, this one helped me:
echo "export WSLENV=HOME/p" >> ~/.profile

WSLENV will forward all passed env variables to wsl, flag \p will convert wsl to windows path.

@TSlivede
Copy link
Contributor

Repeated from rprichard/wslbridge#32 (comment):

@zviryatko
The problem with export WSLENV=HOME/p is that the Windows HOME variable then points to the WSL directory, so git for Windows is then using the .gitconfig of you WSL user. That may or may not be what you want.

@TSlivede
Copy link
Contributor

Repeated from rprichard/wslbridge#32 (comment):

Tested with git-for-windows version 2.25.0.windows.1 and wslbridge-0.2.4-cygwin64:

C:\Users\username>echo %HOME%
%HOME%                                          so HOME is not set in my global environment
C:\Users\username>D:\Programs\Git\bin\git.exe config --global -e
                                                has opened C:/Users/username/.gitconfig
C:\Users\username>D:\ExcludeFromBackup\tmp\wslbridge-0.2.4-cygwin64\wslbridge.exe
User@hostname:/mnt/c/Users/username$ echo $HOME
/home/User
User@hostname:/mnt/c/Users/username$ cmd.exe /c@ echo '%HOME%'
D:\ExcludeFromBackup\tmp\home\username          Windows Environment variable 'HOME' is set to 
                                                a different value than WSL internal 'HOME'
User@hostname:/mnt/c/Users/username$ /mnt/d/Programs/Git/bin/git.exe config --global -e
fatal: cannot create configuration file D:/ExcludeFromBackup/tmp/home/Timo/.gitconfig: No such file or directory
                                                git for Windows looks in Windows Environment variable 'HOME'

The value of Windows Environment variable HOME has the value it had, when WSL was launched, so in this case its the value it had within wslbridge.exe. As wslbridge.exe is a cygwin application, cygwin1.dll startup code ensures, that a proper cygwin environment is present. cygwin1.dll assumes, that the cygwin root directory is one directory above the directory in which cygwin1.dll is located. If HOME is not set, cygwin sets it to cygwin-root\home\username.

Git for Windows checks if HOME is set, and in that case assumes, that its .gitconfig is located there. Otherwise it assumes that .gitconfig is located in the Windows User home directory.

Solution

Create file nsswitch.conf in <path to cygwin1.dll>\..\etc\ containing db_home: <cygwin style path to desired location> (See https://stackoverflow.com/questions/1494658/how-can-i-change-my-cygwin-home-folder-after-installation for nsswitch.conf)

C:\Users\username>mkdir D:\ExcludeFromBackup\tmp\wslbridge-0.2.4-cygwin64\..\etc\
C:\Users\username>echo db_home: /%H > D:\ExcludeFromBackup\tmp\wslbridge-0.2.4-cygwin64\..\etc\nsswitch.conf

/%H means, that the cygwin HOME variable is set to the Windows User home directory, which is the path, where git for Windows otherwise looks by default.

Test

C:\Users\username>D:\ExcludeFromBackup\tmp\wslbridge-0.2.4-cygwin64\wslbridge.exe
User@hostname:/mnt/c/Users/username$ echo $HOME
/home/User
User@hostname:/mnt/c/Users/username$ cmd.exe /c@ echo '%HOME%'
C:\Users\username
User@hostname:/mnt/c/Users/username$ /mnt/d/Programs/Git/bin/git.exe config --global -e
                                                has opened C:/Users/username/.gitconfig

TLDR - Solution in ConEmu:

ConEmu.exe -run "{Shells::Cmd (Admin)}"

Or open admin cmd with ConEmu-variables set in any way. Then:

mkdir "%ConEmuBaseDir%\etc"
echo db_home: /%H > "%ConEmuBaseDir%\etc\nsswitch.conf"
exit

@TSlivede
Copy link
Contributor

@Maximus5
Could you possibly add a file %ConEmuBaseDir%\etc\nsswitch.conf containing db_home: /%H to the standard installation? (Or move current contents of %ConEmuBaseDir%\wsl into %ConEmuBaseDir%\wsl\bin and add %ConEmuBaseDir%\wsl\etc\nsswitch.conf)

The way it is currently, the Windows Environment Variable HOME points to an invalid path when you open WSL with the default wslbridge configuration if you don't have a global Windows Environment Variable HOME set for your user.

For me the problem wasn't with git for Windows, but with pulseaudio:

User@hostname:/mnt/c/Users/username$ /mnt/d/Program\ Files/pulseaudio-1.1/bin/pulseaudio.exe
E: [(null)] pulsecore/core-util.c: Failed to stat home directory D:\PROGRA~3\ConEmu\ConEmu\home\User: No such file or directory

@Maximus5 Maximus5 reopened this Jan 18, 2020
@TSlivede
Copy link
Contributor

Note: A proper solution would somehow ensure, that Windows Environment Variable HOME is not set when launching WSL, if HOME wasn't set before launching wslbridge.

However, I think, that the behavior of the proposed solution is in most situations not problematic: If HOME was already set before launching wslbridge, then it will afterwords still point to the same location. (See point 1. in http://www.cygwin.com/faq.html#faq.setup.home)
If it wasn't set before, it will with this solution at least point to a reasonable path...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants