Skip to content

Commit 47234b6

Browse files
committed
feat: Document gix_testtools::bash_program() and make it public
To make it easier for users of `gix-testtools` to diagnose problems or verify that the fallback for running fixutre scripts without usable shebangs (which is effectively how any fixture shell script is run on Windows), the formerly private `bash_program()` is now public. However, it is not recommend to rely on this specific value or on observed behavior of how it is computed. The details may change at any time. The purpose of `bash_program()` and how it is used internally by `gix-testtools` is also now documented explicitly. Broad details of how it searches or guesses what path to use are likewise documented, with a caveat that changes to them are not considered breaking.
1 parent 9061fc4 commit 47234b6

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

tests/tools/src/lib.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,35 @@ fn configure_command<'a, I: IntoIterator<Item = S>, S: AsRef<OsStr>>(
652652
.env("GIT_CONFIG_VALUE_3", "always")
653653
}
654654

655-
fn bash_program() -> &'static Path {
655+
/// Get the path attempted as a `bash` interpreter, for fixture scripts having no `#!` we can use.
656+
///
657+
/// This is rarely called on Unix-like systems, provided that fixture scripts have usable shebang
658+
/// (`#!`) lines and are marked executable. However, Windows does not recognize `#!` when executing
659+
/// a file. If all fixture scripts that cannot be directly executed are `bash` scripts or can be
660+
/// treated as such, fixture generation still works on Windows, as long as this function manages to
661+
/// find or guess a suitable `bash` interpreter.
662+
///
663+
/// ### Search order
664+
///
665+
/// This function is used internally. It is public to facilitate diagnostic use. The following
666+
/// details are subject to change without warning, and changes are treated as non-breaking.
667+
///
668+
/// The `bash.exe` found in a path search is not always suitable on Windows. This is mainly because
669+
/// `bash.exe` in `System32`, which is associated with WSL, would often be found first. But even
670+
/// where that is not the case, the best `bash.exe` to use to run fixture scripts to set up Git
671+
/// repositories for testing is usually one associated with Git for Windows, even if some other
672+
/// `bash.exe` would be found in a path search. Currently, the search order we use is as follows:
673+
///
674+
/// 1. The shim `bash.exe`, which sets environment variables when run and is, on some systems,
675+
/// needed to find the POSIX utilities that scripts need (or correct versions of them).
676+
///
677+
/// 2. The non-shim `bash.exe`, which is sometimes available even when the shim is not available.
678+
/// This is mainly because the Git for Windows SDK does not come with a `bash.exe` shim.
679+
///
680+
/// 3. As a fallback, the simple name `bash.exe`, which triggers a path search when run.
681+
///
682+
/// On non-Windows systems, the simple name `bash` is used, which triggers a path search when run.
683+
pub fn bash_program() -> &'static Path {
656684
// TODO(deps): Unify with `gix_path::env::shell()` by having both call a more general function
657685
// in `gix-path`. See https://github.com/GitoxideLabs/gitoxide/issues/1886.
658686
static GIT_BASH: Lazy<PathBuf> = Lazy::new(|| {

0 commit comments

Comments
 (0)