Skip to content

Commit 9eaa0d9

Browse files
committed
Make ALTERNATIVE_LOCATIONS dynamic and OsString-based
This is to support a forthcoming fix where the paths will no longer be hard-coded.
1 parent 6cd8b46 commit 9eaa0d9

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

gix-path/src/env/git.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::path::PathBuf;
22
use std::{
3+
ffi::OsString,
34
path::Path,
45
process::{Command, Stdio},
56
};
@@ -8,12 +9,14 @@ use bstr::{BStr, BString, ByteSlice};
89

910
/// Other places to find Git in.
1011
#[cfg(windows)]
11-
pub(super) static ALTERNATIVE_LOCATIONS: &[&str] = &[
12-
"C:/Program Files/Git/mingw64/bin",
13-
"C:/Program Files (x86)/Git/mingw32/bin",
14-
];
12+
pub(super) static ALTERNATIVE_LOCATIONS: once_cell::sync::Lazy<Vec<OsString>> = once_cell::sync::Lazy::new(|| {
13+
vec![
14+
"C:/Program Files/Git/mingw64/bin".into(),
15+
"C:/Program Files (x86)/Git/mingw32/bin".into(),
16+
]
17+
});
1518
#[cfg(not(windows))]
16-
pub(super) static ALTERNATIVE_LOCATIONS: &[&str] = &[];
19+
pub(super) static ALTERNATIVE_LOCATIONS: Lazy<Vec<OsString>> = Lazy::new(|| vec![]);
1720

1821
#[cfg(windows)]
1922
pub(super) static EXE_NAME: &str = "git.exe";
@@ -35,7 +38,7 @@ pub(super) static EXE_INFO: once_cell::sync::Lazy<Option<BString>> = once_cell::
3538
Ok(out) => out.stdout,
3639
#[cfg(windows)]
3740
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
38-
let executable = ALTERNATIVE_LOCATIONS.into_iter().find_map(|prefix| {
41+
let executable = ALTERNATIVE_LOCATIONS.iter().find_map(|prefix| {
3942
let candidate = Path::new(prefix).join(EXE_NAME);
4043
candidate.is_file().then_some(candidate)
4144
})?;

0 commit comments

Comments
 (0)