Hi Marc,
On 2015-07-16 21:47, Marc Strapetz wrote:
> On 16.07.2015 14:59, Johannes Schindelin wrote:
>> On 2015-07-16 14:34, Marc Strapetz wrote:
>>
>>> $ set path="C:\Program Files (x86)\git\bin"
>>> $ bin\bash c:\temp\path.sh
>>> /bin/bin:/bin/mingw/bin:/c/Program Files (x86)/git/bin
>>> git version 2.4.5.windows.1
>>>
>>> Is this behavior expected?
I *just* had time to reproduce the problem.
There are multiple things going on and all of them are important, so
hang on for a while.
The first thing to note is that I made a conscious decision with Git for
Windows 1.x to just slam every executable into /bin/ and be done with
it. This breaks the paradigm of MinGW, though, which makes a very clear
distinction between MinGW executables (i.e. programs using the pure
Win32 API) and MSys executables (i.e. programs relying on the POSIX
emulation of MSys). The former are expected to be in /mingw/bin/ and the
latter in /bin/ for MSys1 (on which Git for Windows 1.x is based).
This was a mistake and the major version jump to 2.x gave me an
excellent opportunity to fix it. Now it is even more complicated,
though: there are *three* bin/ directories: /usr/bin/ for MSys2
executables, /mingw32/bin/ and /mingw64/bin/ for 32-bit and 64-bit
executables, respectively, that do not rely on the POSIX emulation. It
is not possible to mix and match 32-bit and 64-bit MSys2 programs,
though.
For 32-bit Git for Windows, I opted to stay with an all 32-bit
environment, so all the MinGW executables are in /mingw32/bin/. For
64-bit, consequently, they live in /mingw64/bin/.
Now, for backwards-compatibility, I introduced what I call "redirectors"
into the /bin/ directory of Git for Windows 2.x. There is `git.exe`,
`bash.exe` and `sh.exe` in this directory, and nothing else. And those
executables are not the "real things", either: they just execute the
real executables in the correct places, wait for them to exit and then
exit with the same exit status.
So far, so good.
But now when you call `bash`, it auto-mounts /usr/bin/ as /bin/ and
therefore the `git.exe` is not found on the PATH because there is only
/bin/ and /mingw/bin/ (which does not even exist in MSys2) in the PATH.
By the way, /bin/:/mingw/bin/ are prefixed automatically by the MSys2
Bash. The rest of the PATH is translated into POSIX-style paths if
possible.
And that is where the subtle issue lies: if the case matches *exactly*,
then your C:\Program Files (x86)\Git\bin gets translated into /bin/.
Which would be fine... if not for that auto-mount! If you misspell the
path ever so slightly (as far as POSIX is concerned, case mismatches are
real spelling errors), the path gets translated into /c/Program\ Files\
\(x86\)/Git/bin instead... which is not shadowed by that auto-mount!
So you have (at least) two options to handle this:
- you could call `bash --login c:\temp\test.sh`. This will add the
/mingw32/bin/ directory to the PATH and everything works.
- you could set the PATH to C:\Program Files
(x86)\Git\mingw32\bin;C:\Program Files (x86)\usr\bin. Those are the
*correct* locations, i.e. not the /bin/ directory that contains only
redirectors.
You could also just misspell the path ;-)
There are of course a couple more options, even some I would prefer but
they would require a substantial amount of work on your side... Let me
know if you are up for working on some Pull Requests ;-)
Ciao,
Johannes