-
-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
git login shell #1752
git login shell #1752
Changes from all commits
9193b05
7379aaf
4ef3a8d
840c71d
3aff1e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -28,6 +28,23 @@ pub fn installation_config_prefix() -> Option<&'static Path> { | |||||
installation_config().map(git::config_to_base_path) | ||||||
} | ||||||
|
||||||
/// Return the shell that Git would prefer as login shell, the shell to execute Git commands from. | ||||||
/// | ||||||
/// On Windows, this is the `bash.exe` bundled with it, and on Unix it's the shell specified by `SHELL`, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The antecedent of "it" may be ambiguous for readers who are less familiar with Git for Windows. If the function is kept, I suggest adjusting this to:
Suggested change
|
||||||
/// or `None` if it is truly unspecified. | ||||||
pub fn login_shell() -> Option<&'static Path> { | ||||||
static PATH: Lazy<Option<PathBuf>> = Lazy::new(|| { | ||||||
if cfg!(windows) { | ||||||
installation_config_prefix() | ||||||
.and_then(|p| p.parent()) | ||||||
.map(|p| p.join("usr").join("bin").join("bash.exe")) | ||||||
Byron marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} else { | ||||||
std::env::var_os("SHELL").map(PathBuf::from) | ||||||
Byron marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
}); | ||||||
PATH.as_deref() | ||||||
} | ||||||
|
||||||
/// Return the name of the Git executable to invoke it. | ||||||
/// If it's in the `PATH`, it will always be a short name. | ||||||
/// | ||||||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#[test] | ||
fn exe_invocation() { | ||
let actual = gix_path::env::exe_invocation(); | ||
assert!( | ||
!actual.as_os_str().is_empty(), | ||
"it finds something as long as git is installed somewhere on the system (or a default location)" | ||
); | ||
} | ||
|
||
#[test] | ||
fn login_shell() { | ||
// On CI, the $SHELL variable isn't necessarily set. Maybe other ways to get the login shell should be used then. | ||
if !gix_testtools::is_ci::cached() { | ||
assert!(gix_path::env::login_shell() | ||
.expect("There should always be the notion of a shell used by git") | ||
Byron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.exists()); | ||
} | ||
} | ||
|
||
#[test] | ||
fn installation_config() { | ||
assert_ne!( | ||
gix_path::env::installation_config().map(|p| p.components().count()), | ||
gix_path::env::installation_config_prefix().map(|p| p.components().count()), | ||
"the prefix is a bit shorter than the installation config path itself" | ||
); | ||
} | ||
|
||
#[test] | ||
fn system_prefix() { | ||
assert_ne!( | ||
gix_path::env::system_prefix(), | ||
None, | ||
"git should be present when running tests" | ||
); | ||
} | ||
|
||
#[test] | ||
fn home_dir() { | ||
assert_ne!( | ||
gix_path::env::home_dir(), | ||
None, | ||
"we find a home on every system these tests execute" | ||
); | ||
} | ||
|
||
mod xdg_config { | ||
use std::ffi::OsStr; | ||
|
||
#[test] | ||
fn prefers_xdg_config_bases() { | ||
let actual = gix_path::env::xdg_config("test", &mut |n| { | ||
(n == OsStr::new("XDG_CONFIG_HOME")).then(|| "marker".into()) | ||
}) | ||
.expect("set"); | ||
#[cfg(unix)] | ||
assert_eq!(actual.to_str(), Some("marker/git/test")); | ||
#[cfg(windows)] | ||
assert_eq!(actual.to_str(), Some("marker\\git\\test")); | ||
} | ||
|
||
#[test] | ||
fn falls_back_to_home() { | ||
let actual = gix_path::env::xdg_config("test", &mut |n| (n == OsStr::new("HOME")).then(|| "marker".into())) | ||
.expect("set"); | ||
#[cfg(unix)] | ||
assert_eq!(actual.to_str(), Some("marker/.config/git/test")); | ||
#[cfg(windows)] | ||
assert_eq!(actual.to_str(), Some("marker\\.config\\git\\test")); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, only Git for Windows has such a preference, in that its Git Bash environment is intended to be a good environment for running
git
commands from. Even there, the preference is mild, in that the Git for Windows installer defaults to making thegit
command available in the user'sPATH
even outside Git Bash. To the best of my knowledge, no such preference exists on the part of the upstream Git project.This doesn't necessarily mean that a
login_shell
function is not useful. But it is not clear from this description what it should be used for. (Relatedly, some of the existing and planned uses seem to be things it should not be used for.)