andy-5 / wslgit

Use Git installed in Bash on Windows/Windows Subsystem for Linux (WSL) from Windows and Visual Studio Code (VSCode)
MIT License
1.18k stars 59 forks source link

Using BASH_ENV requires WSLGIT_USE_INTERACTIVE_SHELL=0 or script is run twice #70

Closed carlolars closed 5 years ago

carlolars commented 5 years ago

From the Readme it sound like using _BASHENV is an alternative to using _WSLGIT_USE_INTERACTIVESHELL.

But if setting _BASHENV (and ofc sharing via WSLENV) but not setting _WSLGIT_USE_INTERACTIVESHELL to 0 then the script in BASH_ENV is run twice, once non-interactive (i flag not set) and then once interactive (i flag set).

If I set _WSLGIT_USE_INTERACTIVESHELL to 0 then the script in BASH_ENV is just run once non-interactive.

So is the readme misleading or is it not working as intended? Or maybe I have something wrong on my side?

Here is an example where I put .bash_profile, which just sources .bashrc, in BASH_ENV:

C:\Users\carl-oskar\bin>wslgit.exe --version
.bash_profile $-=hBc, BASH_ENV=/c/Users/carl-oskar/.bash_profile
.bashrc $-=hBc, BASH_ENV=/c/Users/carl-oskar/.bash_profile
.bashrc $-=himBHc, BASH_ENV=/c/Users/carl-oskar/.bash_profile
git version 2.17.1

(Both files print their name and the value of $-.) The call to .bash_profile (which does the first call to .bashrc) correctly has $- set to hBc, but the second call to .bashrc has $- set to himBHc.

andy-5 commented 5 years ago

The two approaches are indeed intended to be alternatives. Your results suggest there is a bug somewhere.

What exactly is the value of WSLENV? If there are additional flags, the presence of BASH_ENV is currently not detected correctly, as described in #56 . In that case, it should work if you remove the flag.

Further, you could try to run the following commands from the windows command line:

wsl bash -ic "git --version"
wsl git --version

The first one is roughly what is executed by wslgit in its default configuration, while the second one is executed when either BASH_ENV or WSLGIT_USE_INTERACTIVE_SHELL is set.

carlolars commented 5 years ago

WSLENV=BASH_ENV/up, so same as issue #56.

C:\Users\carl-oskar>echo %WSLENV%
BASH_ENV/up

C:\Users\carl-oskar>bin\wslgit.exe --version
.bashrc hBc
.bashrc himBHc
Using setup for WSL (Linux 4.4.0-17134-Microsoft GNU/Linux)
git version 2.17.1
C:\Users\carl-oskar>echo %WSLENV%
BASH_ENV

C:\Users\carl-oskar>bin\wslgit.exe --version
.bashrc hBc
git version 2.17.1