You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: Check prefix and prefer shim in gix_path::env::shell()
This makes a few changes to make `shell()` more robust:
1. Check the last two components of the path `git --exec-path`
gave, to make sure they are `libexec/git-core`.
(The check is done in such a way that the separator may be `/`
or `\`, though a `\` separator here would be unexpected. We
permit it because it may plausibly be present due to an
overriden `GIT_EXEC_PATH` that breaks with Git's own behavior of
using `/` but that is otherwise fully usable.)
If the directory is not named `git-core`, or it is a top-level
directory (no parent), or its parent is not named `libexec`,
then it is not reasonable to guess that this is in a directory
where it would be safe to use `sh.exe` in the expected relative
location. (Even if safe, such a layout does not suggest that a
`sh.exe` found in it would be better choice than the fallback of
just doing a `PATH` search.)
2. Check the grandparent component (that `../..` would go to) of
the path `git --exec-path` gave, to make sure it is recognized
name of a platform-specific `usr`-like directory that has been
used in MSYS2.
This is to avoid traversing up out of less common directory
trees that have some different and shallower structure than
found in a typical Git for Windows or MSYS2 installation.
3. Instead of using only the `(git root)/usr/bin/sh.exe` non-shim,
prefer the `(git root)/bin/sh.exe` shim. If that is not found,
fall back to the `(git root)/usr/bin/sh.exe` non-shim, mainly to
support the Git for Windows SDK, which doesn't have the shim.
The reason to prefer the shim is that it sets environment
variables, including prepending `bin` directories that provide
tools one would expect to have when using it. Without this,
common POSIX commands may be unavailable, or different and
incompatible implementations of them may be found.
In particular, if they are found in a different MSYS2
installation whose `msys-2.0.dll` is of a different version or
otherwise a different build, then calling them directly may
produce strange behavior. See:
- https://cygwin.com/faq.html#faq.using.multiple-copies
- GitoxideLabs#1862 (comment)
This makes things more robust overall than either preferring the
non-shim or just doing a path search for `sh` as was done before
that. But it exacerbates GitoxideLabs#1868 (as described there), so if the
Git for Windows `sh.exe` shim continues to work as it currently
does, then further improvements may be called for here.
0 commit comments