Skip to content

Commit 9d4dd12

Browse files
committed
fix: Unset other env vars related to GIT_DIR for fixtures
This removes other environment variables that have an effect conceptually related to `GIT_DIR` even when `GIT_DIR` is not set. Most of them change where `git` will look for files that are ordinarily in a repository's `.git` directory. In contrast, `GIT_WORK_TREE` changes where the working tree is found. These would rarely be set in the environment in which the tests are run, but it makes sense to unset them for the same reason as unsetting `GIT_DIR`, which is already done. The new `remove_env` calls are roughly in the order in which the variables they unset are listed in git(1). This deliberately does not attempt to unset every possible environment variable that git(1) documents as affecting its behavior. This is for four reasons: - Some variables may be set on the test machine without envisioning this usage, but should still be kept, such as those that cause more or less traversal than usual to be done. For example, if `GIT_CEILING_DIRECTORIES` or even `GIT_DISCOVERY_ACROSS_FILESYSTEM` are set, it may be for a good reason. - Some variables will have no default unless other variables that are being modified here are changed again after the changes here. In particular, `GIT_CONFIG_SYSTEM` only has an effect if `GIT_CONFIG_NOSYSTEM` is not set. We set `GIT_CONFIG_NOSYSTEM` to `1`, so if it is unset then a fixture script has unset it, in which case it is presumably intended that `GIT_CONFIG_SYSTEM` have some effect (if the fixture script doesn't change/unset it). - Some variables are useful for extra debugging and make sense to set when running the test fixtures under foreseeable conditions. For example, the effects of all `GIT_TRACE*` variables are intentionally preserved. - For a few variables, such as `GIT_DEFAULT_HASH`, it is unlikely that they would be wanted in the test environment, but even more unlikely that they would be set in that environment without the intention of experimenting with their effect on fixtures. However, this is not to say that all environment variables that would make sense to remove have necessarily been removed. The removed variables here differ from those removed for the `git` invocation in `gix-path/src/env/git/mod.rs` for two reasons: - That is a single `git` invocation for a specific command, so the environment variables that ought to affect it must be kept, and others can be removed. But here, arbitrary fixtures need to work, and they provide almost all of their own environment as needed. - Setting an unusual value of `GIT_DIR` there that `git` cannot take to be a usable repository also prevents the variables that override `GIT_DIR` for specific files from being used. (But maybe those should be unset there anyway, for clarity?)
1 parent d69c617 commit 9d4dd12

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tests/tools/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,11 @@ fn configure_command<'a>(
600600
.stderr(std::process::Stdio::piped())
601601
.current_dir(script_result_directory)
602602
.env_remove("GIT_DIR")
603+
.env_remove("GIT_INDEX_FILE")
604+
.env_remove("GIT_OBJECT_DIRECTORY")
605+
.env_remove("GIT_ALTERNATE_OBJECT_DIRECTORIES")
606+
.env_remove("GIT_WORK_TREE")
607+
.env_remove("GIT_COMMON_DIR")
603608
.env_remove("GIT_ASKPASS")
604609
.env_remove("SSH_ASKPASS")
605610
.env("MSYS", msys_for_git_bash_on_windows)

0 commit comments

Comments
 (0)