|
1 |
| -use std::ffi::OsString; |
| 1 | +use std::ffi::{OsStr, OsString}; |
2 | 2 | use std::path::{Path, PathBuf};
|
3 | 3 |
|
4 | 4 | use bstr::{BString, ByteSlice};
|
@@ -28,21 +28,25 @@ pub fn installation_config_prefix() -> Option<&'static Path> {
|
28 | 28 | installation_config().map(git::config_to_base_path)
|
29 | 29 | }
|
30 | 30 |
|
31 |
| -/// Return the shell that Git would prefer as login shell, the shell to execute Git commands from. |
| 31 | +/// Return the shell that Git would use, the shell to execute commands from. |
32 | 32 | ///
|
33 |
| -/// On Windows, this is the `bash.exe` bundled with it, and on Unix it's the shell specified by `SHELL`, |
34 |
| -/// or `None` if it is truly unspecified. |
35 |
| -pub fn login_shell() -> Option<&'static Path> { |
36 |
| - static PATH: Lazy<Option<PathBuf>> = Lazy::new(|| { |
| 33 | +/// On Windows, this is the full path to `sh.exe` bundled with it, and on |
| 34 | +/// Unix it's `/bin/sh` as posix compatible shell. |
| 35 | +/// If the bundled shell on Windows cannot be found, `sh` is returned as the name of a shell |
| 36 | +/// as it could possibly be found in `PATH`. |
| 37 | +/// Note that the returned path might not be a path on disk. |
| 38 | +pub fn shell() -> &'static OsStr { |
| 39 | + static PATH: Lazy<Option<OsString>> = Lazy::new(|| { |
37 | 40 | if cfg!(windows) {
|
38 | 41 | installation_config_prefix()
|
39 | 42 | .and_then(|p| p.parent())
|
40 |
| - .map(|p| p.join("usr").join("bin").join("bash.exe")) |
| 43 | + .map(|p| p.join("usr").join("bin").join("sh.exe")) |
| 44 | + .map(Into::into) |
41 | 45 | } else {
|
42 |
| - std::env::var_os("SHELL").map(PathBuf::from) |
| 46 | + Some("/bin/sh".into()) |
43 | 47 | }
|
44 | 48 | });
|
45 |
| - PATH.as_deref() |
| 49 | + PATH.as_deref().unwrap_or(OsStr::new("sh")) |
46 | 50 | }
|
47 | 51 |
|
48 | 52 | /// Return the name of the Git executable to invoke it.
|
|
0 commit comments