Skip to content

Commit e30c070

Browse files
committed
Use consistent git command name in gix-testtools
In the test tools, this always runs the `git` program as `git.exe` on Windows, while continuing always to run it as `git` on other systems. Prior to this change, on Windows `gix-testtools` used `git` in some operations and `git.exe` in others: - `parse_git_version` used `git.exe`. - Other functions used `git`. - For the git daemon, `git-daemon.exe` was used. For the way `gix-testtools` uses the `git` program, it would be fine to call it `git` on all platforms. For example, it does not form full paths to the executable that have to be found to exist in operations other than running it. (For running it, the `.exe` suffix is allowed to be omitted.) So it would probably be fine to use the even simpler logic of having it be `git` everywhere. But since `git.exe` was sometimes used, `git-daemon.exe` was used, and using `git.exe` is more similar to the behavior in `git-path`, it is changed to use `git.exe` when the platform is Windows. Because `gix-testtools` does not depend on `gix-path`, it doesn't use `gix_path::env::exe_invocation` to decide how to call `git`. That keeps it from finding `git` in some Windows environments (those where `git` is in a standard/predictable location but not in `PATH`). This change has no effect on that limitation.
1 parent 01737ad commit e30c070

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

tests/tools/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl Drop for GitDaemon {
5959
}
6060

6161
static SCRIPT_IDENTITY: Lazy<Mutex<BTreeMap<PathBuf, u32>>> = Lazy::new(|| Mutex::new(BTreeMap::new()));
62+
6263
static EXCLUDE_LUT: Lazy<Mutex<Option<gix_worktree::Stack>>> = Lazy::new(|| {
6364
let cache = (|| {
6465
let (repo_path, _) = gix_discover::upwards(Path::new(".")).ok()?;
@@ -86,6 +87,12 @@ static EXCLUDE_LUT: Lazy<Mutex<Option<gix_worktree::Stack>>> = Lazy::new(|| {
8687
})();
8788
Mutex::new(cache)
8889
});
90+
91+
#[cfg(windows)]
92+
const GIT_PROGRAM: &str = "git.exe";
93+
#[cfg(not(windows))]
94+
const GIT_PROGRAM: &str = "git";
95+
8996
/// The major, minor and patch level of the git version on the system.
9097
pub static GIT_VERSION: Lazy<(u8, u8, u8)> = Lazy::new(|| parse_git_version().expect("git version to be parsable"));
9198

@@ -117,9 +124,7 @@ pub fn should_skip_as_git_version_is_smaller_than(major: u8, minor: u8, patch: u
117124
}
118125

119126
fn parse_git_version() -> Result<(u8, u8, u8)> {
120-
let git_program = cfg!(windows).then(|| "git.exe").unwrap_or("git");
121-
let output = std::process::Command::new(git_program).arg("--version").output()?;
122-
127+
let output = std::process::Command::new(GIT_PROGRAM).arg("--version").output()?;
123128
git_version_from_bytes(&output.stdout)
124129
}
125130

@@ -173,7 +178,7 @@ impl Drop for AutoRevertToPreviousCWD {
173178

174179
/// Run `git` in `working_dir` with all provided `args`.
175180
pub fn run_git(working_dir: &Path, args: &[&str]) -> std::io::Result<std::process::ExitStatus> {
176-
std::process::Command::new("git")
181+
std::process::Command::new(GIT_PROGRAM)
177182
.current_dir(working_dir)
178183
.args(args)
179184
.status()
@@ -182,7 +187,7 @@ pub fn run_git(working_dir: &Path, args: &[&str]) -> std::io::Result<std::proces
182187
/// Spawn a git daemon process to host all repository at or below `working_dir`.
183188
pub fn spawn_git_daemon(working_dir: impl AsRef<Path>) -> std::io::Result<GitDaemon> {
184189
static EXEC_PATH: Lazy<PathBuf> = Lazy::new(|| {
185-
let path = std::process::Command::new("git")
190+
let path = std::process::Command::new(GIT_PROGRAM)
186191
.arg("--exec-path")
187192
.stderr(std::process::Stdio::null())
188193
.output()
@@ -738,7 +743,7 @@ fn populate_meta_dir(destination_dir: &Path, script_identity: u32) -> std::io::R
738743
)?;
739744
std::fs::write(
740745
meta_dir.join(META_GIT_VERSION),
741-
std::process::Command::new("git").arg("--version").output()?.stdout,
746+
std::process::Command::new(GIT_PROGRAM).arg("--version").output()?.stdout,
742747
)?;
743748
Ok(meta_dir)
744749
}
@@ -951,7 +956,7 @@ mod tests {
951956
let temp = tempfile::TempDir::new().expect("can create temp dir");
952957
populate_ad_hoc_config_files(temp.path());
953958

954-
let mut cmd = std::process::Command::new("git");
959+
let mut cmd = std::process::Command::new(GIT_PROGRAM);
955960
cmd.env("GIT_CONFIG_SYSTEM", SCOPE_ENV_VALUE);
956961
cmd.env("GIT_CONFIG_GLOBAL", SCOPE_ENV_VALUE);
957962
configure_command(&mut cmd, ["config", "-l", "--show-origin"], temp.path());

0 commit comments

Comments
 (0)