Skip to content

Commit

Permalink
More robust localization of sh.exe on Windows
Browse files Browse the repository at this point in the history
Here is what @EliahKagan wrote:

> While it sometimes works, I don't think this technique is a reliable way of finding the `bash.exe` associated with Git for Windows. If I recall correctly, `installation_config_prefix()` is based on the location of the highest scoped non-local non-worktree configuration file of those that supply at least one configuration variable, except in the case of the `EXEPATH` optimization, which in practice only works in a Git Bash environment (and not always reliably).
>
> Git for Windows installations usually have variables configured in the system scope, but this is not guaranteed. That scope may also be suppressed by `GIT_CONFIG_NOSYSTEM` or have its associated configuration file set to a custom path by `GIT_CONFIG_SYSTEM`. In any of those cases, we may get no path but, currently, we are more likely to get a different path that would not be correct here, because while the local and worktree scopes are excluded, the global scope is not.
>
> Although it is valuable to perform fewer subprocess invocations on Windows where they can be slow, I don't think a technique along these lines for finding the `bash.exe` associated with a Git for Windows installation can be made reliable. The only reliable approach I know of is to infer the path from the output of `git --exec-path`, as in #1712.
>
> (If it is necessary to eke out a little extra performance, then it might be possible to attempt another approach while carefully covering cases where it does not work and checking for signs that it may be inaccurate, while still falling back to an `--exec-path`-based way.)

Note that there is no attempt to eke out more performance yet.
  • Loading branch information
Byron committed Jan 11, 2025
1 parent 75d689f commit 3fdc68e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gix-path/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub fn installation_config_prefix() -> Option<&'static Path> {
pub fn shell() -> &'static OsStr {
static PATH: Lazy<Option<OsString>> = Lazy::new(|| {
if cfg!(windows) {
installation_config_prefix()
.and_then(|p| p.parent())
core_dir()
.and_then(|p| p.ancestors().nth(3) /* skip mingw64/libexec/git-core */)
.map(|p| p.join("usr").join("bin").join("sh.exe"))
.map(Into::into)
} else {
Expand Down

0 comments on commit 3fdc68e

Please sign in to comment.