Skip to content

Commit 5e783de

Browse files
authored
Merge pull request #1592 from EliahKagan/tools-cfgcmd
Make `configure_command` easier to call and comment about `MSYS`
2 parents 4f92140 + 4a25ef5 commit 5e783de

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tests/tools/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::{
1212
collections::BTreeMap,
1313
env,
14-
ffi::OsString,
14+
ffi::{OsStr, OsString},
1515
io::Read,
1616
path::{Path, PathBuf},
1717
str::FromStr,
@@ -589,11 +589,14 @@ const NULL_DEVICE: &str = "NUL";
589589
#[cfg(not(windows))]
590590
const NULL_DEVICE: &str = "/dev/null";
591591

592-
fn configure_command<'a>(
592+
fn configure_command<'a, I: IntoIterator<Item = S>, S: AsRef<OsStr>>(
593593
cmd: &'a mut std::process::Command,
594-
args: &[String],
594+
args: I,
595595
script_result_directory: &Path,
596596
) -> &'a mut std::process::Command {
597+
// For simplicity, we extend the `MSYS` variable from from our own environment. This disregards
598+
// state from any prior `cmd.env("MSYS")` or `cmd.env_remove("MSYS")` calls. Such calls should
599+
// either be avoided, or made after this function returns (but before spawning the command).
597600
let mut msys_for_git_bash_on_windows = env::var_os("MSYS").unwrap_or_default();
598601
msys_for_git_bash_on_windows.push(" winsymlinks:nativestrict");
599602
cmd.args(args)
@@ -925,10 +928,9 @@ mod tests {
925928
populate_ad_hoc_config_files(temp.path());
926929

927930
let mut cmd = std::process::Command::new("git");
928-
let args = ["config", "-l", "--show-origin"].map(String::from);
929931
cmd.env("GIT_CONFIG_SYSTEM", SCOPE_ENV_VALUE);
930932
cmd.env("GIT_CONFIG_GLOBAL", SCOPE_ENV_VALUE);
931-
configure_command(&mut cmd, &args, temp.path());
933+
configure_command(&mut cmd, ["config", "-l", "--show-origin"], temp.path());
932934

933935
let output = cmd.output().expect("can run git");
934936
let lines: Vec<_> = output

0 commit comments

Comments
 (0)