Skip to content

Commit 1866a52

Browse files
committed
use gix_path::env::executable_invocation() where possible.
That way we are more likely to find Git even on platforms that don't have a reliable PATH.
1 parent 09fd2c4 commit 1866a52

File tree

7 files changed

+19
-17
lines changed

7 files changed

+19
-17
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gitoxide-core/src/repository/attributes/validate_baseline.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub(crate) mod function {
7474
let tx_base = tx_base.clone();
7575
let mut progress = progress.add_child("attributes");
7676
move || -> anyhow::Result<()> {
77-
let mut child = std::process::Command::new(GIT_NAME)
77+
let mut child = std::process::Command::new(gix::path::env::exe_invocation())
7878
.args(["check-attr", "--stdin", "-a"])
7979
.stdin(std::process::Stdio::piped())
8080
.stdout(std::process::Stdio::piped())
@@ -125,7 +125,7 @@ pub(crate) mod function {
125125
let tx_base = tx_base.clone();
126126
let mut progress = progress.add_child("excludes");
127127
move || -> anyhow::Result<()> {
128-
let mut child = std::process::Command::new(GIT_NAME)
128+
let mut child = std::process::Command::new(gix::path::env::exe_invocation())
129129
.args(["check-ignore", "--stdin", "-nv", "--no-index"])
130130
.stdin(std::process::Stdio::piped())
131131
.stdout(std::process::Stdio::piped())
@@ -254,8 +254,6 @@ pub(crate) mod function {
254254
}
255255
}
256256

257-
static GIT_NAME: &str = if cfg!(windows) { "git.exe" } else { "git" };
258-
259257
enum Baseline {
260258
Attribute { assignments: Vec<gix::attrs::Assignment> },
261259
Exclude { location: Option<ExcludeLocation> },

gix-credentials/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ gix-trace = { version = "^0.1.8", path = "../gix-trace" }
2727

2828
thiserror = "1.0.32"
2929
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
30-
bstr = { version = "1.3.0", default-features = false, features = ["std"]}
30+
bstr = { version = "1.3.0", default-features = false, features = ["std"] }
3131

3232

3333

@@ -36,6 +36,7 @@ document-features = { version = "0.2.1", optional = true }
3636
[dev-dependencies]
3737
gix-testtools = { path = "../tests/tools" }
3838
gix-sec = { path = "../gix-sec" }
39+
once_cell = "1.19.0"
3940

4041
[package.metadata.docs.rs]
4142
all-features = true

gix-credentials/src/program/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl Program {
6868

6969
/// Convert the program into the respective command, suitable to invoke `action`.
7070
pub fn to_command(&self, action: &helper::Action) -> std::process::Command {
71-
let git_program = cfg!(windows).then(|| "git.exe").unwrap_or("git");
71+
let git_program = gix_path::env::exe_invocation();
7272
let mut cmd = match &self.kind {
7373
Kind::Builtin => {
7474
let mut cmd = Command::new(git_program);
@@ -79,7 +79,7 @@ impl Program {
7979
let mut args = name_and_args.clone();
8080
args.insert_str(0, "credential-");
8181
args.insert_str(0, " ");
82-
args.insert_str(0, git_program);
82+
args.insert_str(0, git_program.to_string_lossy().as_ref());
8383
gix_command::prepare(gix_path::from_bstr(args.as_ref()).into_owned())
8484
.arg(action.as_arg(true))
8585
.with_shell_allow_argument_splitting()

gix-credentials/tests/program/from_custom_definition.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use gix_credentials::{helper, program::Kind, Program};
22

3-
#[cfg(windows)]
4-
const GIT: &str = "git.exe";
5-
#[cfg(not(windows))]
6-
const GIT: &str = "git";
3+
static GIT: once_cell::sync::Lazy<&'static str> =
4+
once_cell::sync::Lazy::new(|| gix_path::env::exe_invocation().to_str().expect("not illformed"));
75

86
#[cfg(windows)]
97
const SH: &str = "sh";
@@ -13,10 +11,11 @@ const SH: &str = "/bin/sh";
1311
#[test]
1412
fn empty() {
1513
let prog = Program::from_custom_definition("");
14+
let git = *GIT;
1615
assert!(matches!(&prog.kind, Kind::ExternalName { name_and_args } if name_and_args == ""));
1716
assert_eq!(
1817
format!("{:?}", prog.to_command(&helper::Action::Store("egal".into()))),
19-
format!(r#""{GIT}" "credential-" "store""#),
18+
format!(r#""{git}" "credential-" "store""#),
2019
"not useful, but allowed, would have to be caught elsewhere"
2120
);
2221
}
@@ -36,32 +35,35 @@ fn simple_script_in_path() {
3635
fn name_with_args() {
3736
let input = "name --arg --bar=\"a b\"";
3837
let prog = Program::from_custom_definition(input);
38+
let git = *GIT;
3939
assert!(matches!(&prog.kind, Kind::ExternalName{name_and_args} if name_and_args == input));
4040
assert_eq!(
4141
format!("{:?}", prog.to_command(&helper::Action::Store("egal".into()))),
42-
format!(r#""{GIT}" "credential-name" "--arg" "--bar=a b" "store""#)
42+
format!(r#""{git}" "credential-name" "--arg" "--bar=a b" "store""#)
4343
);
4444
}
4545

4646
#[test]
4747
fn name_with_special_args() {
4848
let input = "name --arg --bar=~/folder/in/home";
4949
let prog = Program::from_custom_definition(input);
50+
let git = *GIT;
5051
assert!(matches!(&prog.kind, Kind::ExternalName{name_and_args} if name_and_args == input));
5152
assert_eq!(
5253
format!("{:?}", prog.to_command(&helper::Action::Store("egal".into()))),
53-
format!(r#""{SH}" "-c" "{GIT} credential-name --arg --bar=~/folder/in/home \"$@\"" "--" "store""#)
54+
format!(r#""{SH}" "-c" "{git} credential-name --arg --bar=~/folder/in/home \"$@\"" "--" "store""#)
5455
);
5556
}
5657

5758
#[test]
5859
fn name() {
5960
let input = "name";
6061
let prog = Program::from_custom_definition(input);
62+
let git = *GIT;
6163
assert!(matches!(&prog.kind, Kind::ExternalName{name_and_args} if name_and_args == input));
6264
assert_eq!(
6365
format!("{:?}", prog.to_command(&helper::Action::Store("egal".into()))),
64-
format!(r#""{GIT}" "credential-name" "store""#),
66+
format!(r#""{git}" "credential-name" "store""#),
6567
"we detect that this can run without shell, which is also more portable on windows"
6668
);
6769
}

gix-path/src/env/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn xdg_config(file: &str, env_var: &mut dyn FnMut(&str) -> Option<OsString>)
8989
///
9090
/// ### Performance
9191
///
92-
/// On windows, the slowest part is the launch of the `git.exe` executable in the PATH, which only happens when launched
92+
/// On windows, the slowest part is the launch of the Git executable in the PATH, which only happens when launched
9393
/// from outside of the `msys2` shell.
9494
///
9595
/// ### When `None` is returned

gix-path/tests/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mod home_dir {
1616

1717
mod env {
1818
#[test]
19-
fn executable_invocation() {
19+
fn exe_invocation() {
2020
let actual = gix_path::env::exe_invocation();
2121
assert!(
2222
!actual.as_os_str().is_empty(),

0 commit comments

Comments
 (0)