Skip to content

Commit 0b45baf

Browse files
committed
feat: Look for bash in (git root)/bin, then (git root)/usr/bin
This changes `bash_program()` so that it will find the `bash.exe` provided by Git for Windows that is most reliable for our use in runinng test fixture scripts, of those that are available. First it uses the shim, but falls back to the non-shim if the shim is not available. If neither is found, then the fallback of using the simple command `bash.exe` (which triggers a path search when run) continues to be used.
1 parent d290ad9 commit 0b45baf

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

tests/tools/src/lib.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -653,21 +653,25 @@ fn configure_command<'a, I: IntoIterator<Item = S>, S: AsRef<OsStr>>(
653653
}
654654

655655
fn bash_program() -> &'static Path {
656-
// TODO(deps): *Maybe* add something to `gix-path` like `env::shell()` that can be used to
657-
// find bash and, once the version `gix-testtools` depends on has it, use it.
656+
// TODO(deps): Unify with `gix_path::env::shell()` by having both call a more general function
657+
// in `gix-path`. See https://github.com/GitoxideLabs/gitoxide/issues/1886.
658658
static GIT_BASH: Lazy<PathBuf> = Lazy::new(|| {
659659
if cfg!(windows) {
660660
GIT_CORE_DIR
661661
.ancestors()
662662
.nth(3)
663-
.map(OsString::from)
664-
.map(|mut raw_path| {
665-
// Go down to where `bash.exe` usually is. Keep using `/` separators (not `\`).
666-
raw_path.push("/usr/bin/bash.exe");
667-
raw_path
663+
.map(OsStr::new)
664+
.iter()
665+
.flat_map(|prefix| {
666+
// Go down to places `bash.exe` usually is. Keep using `/` separators, not `\`.
667+
["/bin/bash.exe", "/usr/bin/bash.exe"].into_iter().map(|suffix| {
668+
let mut raw_path = (*prefix).to_owned();
669+
raw_path.push(suffix);
670+
raw_path
671+
})
668672
})
669673
.map(PathBuf::from)
670-
.filter(|bash| bash.is_file())
674+
.find(|bash| bash.is_file())
671675
.unwrap_or_else(|| "bash.exe".into())
672676
} else {
673677
"bash".into()

0 commit comments

Comments
 (0)