History

fix: Omit system/global config in fixtures regardless of contents

This uses the null device, `/dev/null` on Unix-like systems and `NUL` on Windows, as the value of `GIT_CONFIG_SYSTEM` and `GIT_CONFIG_GLOBAL` when `gix-testtols` runs test fixture shell scripts. `/dev/null` is explicitly recommended for this purpose, when setting those environment variables for the purpose of preventing configuration files from being read, in the Git documentation: - https://git-scm.com/docs/git#Documentation/git.txt-codeGITCONFIGGLOBALcode On Windows, `NUL` is an analogue of `/dev/null`. Even in the unusual scenario that a `\\?\` prefixed UNC path is used to create an actual file named `NUL` in the directory the fixture script operates in, the relative path `NUL` still resolves to the null device and not to that file. The previous behavior was to use a value of `:` on Unix-like systems or `-` on Windows. But these were really just unusual but valid paths, such that files of those names could exist in any location. `git` furthermore treats them as paths: a `:` is not special in these environment variables because they hold a single path rather than a list of paths, and a `-` is not special (for example, it does not specify stdin) because it appears in an environment variable rather than a command-line argument. While `:` and `-` are unusual filenames, this code is used in testing, including of edge cases where unusual files may be used. So this change may make the test tools slightly more robust.

Eliah Kagan committed 2 years ago

Commit 3cf9fc11 parent d7dca271 file · +7 −3Browse files

Unified · Split

tests/tools/src/lib.rs+7−3
@@ -583,12 +583,16 @@ fn scripted_fixture_read_only_with_args_inner( · 582 unmodified lines
583583 Ok(script_result_directory)
584584 }
585585
586+#[cfg(windows)]
587+const NULL_DEVICE: &str = "NUL";
588+#[cfg(not(windows))]
589+const NULL_DEVICE: &str = "/dev/null";
590+
586591 fn configure_command<'a>(
587592 cmd: &'a mut std::process::Command,
588593 args: &[String],
589594 script_result_directory: &Path,
590595 ) -> &'a mut std::process::Command {
591− let never_path = if cfg!(windows) { "-" } else { ":" };
592596 let mut msys_for_git_bash_on_windows = std::env::var("MSYS").unwrap_or_default();
593597 msys_for_git_bash_on_windows.push_str(" winsymlinks:nativestrict");
594598 cmd.args(args)
@@ -599,8 +603,8 @@ fn configure_command<'a>( · 4 unmodified lines
599603 .env_remove("GIT_ASKPASS")
600604 .env_remove("SSH_ASKPASS")
601605 .env("MSYS", msys_for_git_bash_on_windows)
602− .env("GIT_CONFIG_SYSTEM", never_path)
603− .env("GIT_CONFIG_GLOBAL", never_path)
606+ .env("GIT_CONFIG_SYSTEM", NULL_DEVICE)
607+ .env("GIT_CONFIG_GLOBAL", NULL_DEVICE)
604608 .env("GIT_TERMINAL_PROMPT", "false")
605609 .env("GIT_AUTHOR_DATE", "2000-01-01 00:00:00 +0000")
606610 .env("GIT_AUTHOR_EMAIL", "author@example.com")