Skip to content

Commit 51bbb86

Browse files
committed
fix: rename env::login_shell() to shell() and explain what it is.
This assures we don't suggest the usage of actual login shells to ever be used to execute hooks. Note that this is not marked as breaking change as no release was made with the old name yet.
1 parent f18a312 commit 51bbb86

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

gix-path/src/env/mod.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::ffi::OsString;
1+
use std::ffi::{OsStr, OsString};
22
use std::path::{Path, PathBuf};
33

44
use bstr::{BString, ByteSlice};
@@ -28,21 +28,25 @@ pub fn installation_config_prefix() -> Option<&'static Path> {
2828
installation_config().map(git::config_to_base_path)
2929
}
3030

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.
3232
///
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(|| {
3740
if cfg!(windows) {
3841
installation_config_prefix()
3942
.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)
4145
} else {
42-
std::env::var_os("SHELL").map(PathBuf::from)
46+
Some("/bin/sh".into())
4347
}
4448
});
45-
PATH.as_deref()
49+
PATH.as_deref().unwrap_or(OsStr::new("sh"))
4650
}
4751

4852
/// Return the name of the Git executable to invoke it.

gix-path/tests/path/env.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ fn exe_invocation() {
88
}
99

1010
#[test]
11-
fn login_shell() {
12-
// On CI, the $SHELL variable isn't necessarily set. Maybe other ways to get the login shell should be used then.
13-
if !gix_testtools::is_ci::cached() {
14-
assert!(gix_path::env::login_shell()
15-
.expect("There should always be the notion of a shell used by git")
16-
.exists());
17-
}
11+
fn shell() {
12+
assert!(
13+
std::path::Path::new(gix_path::env::shell()).exists(),
14+
"On CI and on Unix we'd expect a full path to the shell that exists on disk"
15+
);
1816
}
1917

2018
#[test]

0 commit comments

Comments
 (0)