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: Use / in gix_path::env::shell() and check existence
This makes the path returned by `gix_path::env::shell()` on Windows
more usable by:
1. Adding components with `/` separators. While in principle a `\`
should work, the path of the shell itself is used in shell
scripts (script files and `sh -c` operands) that may not account
for the presence of backslashes, and it is also harder to read
paths with `\` in contexts where it appears escaped, which may
include various messages from Rust code and shell scripts.
The path before what we add will already use `/` and never `\`,
unless `GIT_EXEC_PATH` has been set to a strange value, because
it is based on `git --exec-path`, which by default gives a path
with `/` separators. Thus, ensuring that the part we add uses `/`
should be sufficient to get a path without `\` in all cases when
it is clearly reasonable to do so. This therefore also usually
increases stylistic consistency of the path, which is another
factor that makes it more user-friendly in messages.
This is needed to get tests to pass since changing `gix-command`
to use `gix_path::env::shell()` on Windows, where a path is
formatted in away that sometimes quotes `\` characters. Their
expectations could be adjusted, but it seems likely that various
other software, much of which may otherwise be working, has
similar expectations. Using `/` instead of `\` works whether `\`
is expected to be displayed quoted or not.
2. Check that the path to the shell plausibly has a shell there,
only using it if it a file or a non-broken file symlink. When
this is not the case, the fallback short name is used instead.
3. The fallback short name is changed from `sh` to `sh.exe`, since
the `.exe` suffix is appended in other short names on Windows,
such as `git.exe`, as well as being part of the filename
component of the path we build for the shell when using the
implementation provided as part of Git for Windows.
Those changes only affect Windows.
This also adds tests for (1) and (2) above, as well as for the
expectation that we get an absolute path, to make sure we don't
build a path that would be absolute on a Unix-like system but is
relative on Windows (a path that starts with just one `/` or `\`).
These tests are not Windows-specific, since all these expectations
should already hold on Unix-like systems, where currently we are
using the hard-coded path `/bin/sh`, which is an absolute path on
those systems. (Some Unix-like systems may technically not have
`/bin/sh` or it may not be the best path to use for a shell that
should be POSIX-compatible, but we are already relying on this,
and handling that better is outside the scope of the changes here.)
0 commit comments