Skip to content

Commit 8f6d39d

Browse files
committed
Unset a couple env vars just in case
I think that, when `GIT_DIR` is set to a location `git` cannot read any repository information from, then `GIT_COMMON_DIR` is not used for "common" parts like `config` either. But I haven't found this documented anywhere and I'm not sure it's guaranteed. So this unsets `GIT_COMMON_DIR`, to avoid reading local-scope configuration for any repository. This also unsets `GIT_DISCOVERY_ACROSS_FILESYSTEM`, which shouldn't be necessary to avoid reading local configuration, but I think at least some versions of Git on some systems will traverse upward from the current directory even when `GIT_DIR` is specified (even though they won't consider us to be in a repository found in the traversal). Unsetting it causes the default of false to be used. This still does not clear all or most of the environment, nor does it attempt to unset all variables that affect `git` behavior, because some variables should be honored to change what we regard to be the configuration associated with the installation, e.g., `GIT_CONFIG_SYSTEM`, while others should be honored for debugging related effects.
1 parent b827813 commit 8f6d39d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

gix-path/src/env/git/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ fn git_cmd(executable: PathBuf) -> Command {
140140
// scope. Although `GIT_CONFIG_NOSYSTEM` will suppress this as well, passing --system omits it.
141141
cmd.args(["config", "-lz", "--show-origin", "--name-only"])
142142
.current_dir(cwd)
143+
.env_remove("GIT_COMMON_DIR") // We are setting `GIT_DIR`.
144+
.env_remove("GIT_DISCOVERY_ACROSS_FILESYSTEM")
143145
.env("GIT_DIR", NULL_DEVICE) // Avoid getting local-scope config.
144-
.env("GIT_WORK_TREE", NULL_DEVICE) // This is just to avoid confusion when debugging.
146+
.env("GIT_WORK_TREE", NULL_DEVICE) // Avoid confusion when debugging.
145147
.stdin(Stdio::null())
146148
.stderr(Stdio::null());
147149
cmd

0 commit comments

Comments
 (0)