pub struct Environment {Show 46 fields
pub cwd: PathBuf,
pub git_dir: Option<String>,
pub git_work_tree: Option<String>,
pub git_ceiling_directories: Option<String>,
pub git_index_file: Option<String>,
pub git_namespace: Option<String>,
pub git_replace_ref_base: Option<String>,
pub git_no_replace_objects: bool,
pub git_alternate_object_directories: Option<String>,
pub git_object_directory: Option<String>,
pub git_prefix: Option<String>,
pub git_config_nosystem: Option<String>,
pub git_config_system: Option<String>,
pub git_config_global: Option<String>,
pub git_config: Option<String>,
pub git_config_parameters: Option<String>,
pub git_config_count: Option<String>,
pub git_config_pairs: Vec<(String, String)>,
pub home: Option<OsString>,
pub xdg_config_home: Option<String>,
pub userprofile: Option<OsString>,
pub homedrive: Option<OsString>,
pub homepath: Option<OsString>,
pub git_install_root: Option<OsString>,
pub git_exec_path: Option<OsString>,
pub pwd: Option<String>,
pub git_test_assume_different_owner: Option<String>,
pub grit_debug_safe_dir: bool,
pub git_trace_setup: Option<String>,
pub git_trace2_perf: Option<String>,
pub grit_invocation_cwd: Option<String>,
pub sudo_uid: Option<String>,
pub git_test_utf8_nfd_to_nfc: Option<String>,
pub git_test_no_write_rev_index: Option<String>,
pub git_test_reftable_autocompaction: Option<String>,
pub git_author_name: Option<String>,
pub git_author_email: Option<String>,
pub git_author_date: Option<String>,
pub git_committer_name: Option<String>,
pub git_committer_email: Option<String>,
pub git_committer_date: Option<String>,
pub tz: Option<String>,
pub user: Option<String>,
pub username: Option<String>,
pub program_files: Option<String>,
pub program_files_x86: Option<String>,
/* private fields */
}Expand description
Discovery and config variables that affect repository open/discover and ConfigSet loading.
Fields§
§cwd: PathBufProcess working directory used for relative path resolution during discovery.
git_dir: Option<String>Override for GIT_DIR when set (see Git environment variable of the same name).
git_work_tree: Option<String>Override for GIT_WORK_TREE when set (see Git environment variable of the same name).
git_ceiling_directories: Option<String>Override for GIT_CEILING_DIRECTORIES when set (see Git environment variable of the same name).
git_index_file: Option<String>Override for GIT_INDEX_FILE when set (see Git environment variable of the same name).
git_namespace: Option<String>Override for GIT_NAMESPACE when set (see Git environment variable of the same name).
git_replace_ref_base: Option<String>Override for GIT_REPLACE_REF_BASE when set (see Git environment variable of the same name).
git_no_replace_objects: boolWhen true, replacement objects from GIT_REPLACE_OBJECT are ignored.
git_alternate_object_directories: Option<String>Override for GIT_ALTERNATE_OBJECT_DIRECTORIES when set (see Git environment variable of the same name).
git_object_directory: Option<String>Override for GIT_OBJECT_DIRECTORY when set (see Git environment variable of the same name).
When set, a Repository opened with this environment reads
and writes objects in this directory instead of <git-dir>/objects (a relative path
resolves against Self::cwd). The directory must exist, or opening fails with
Error::NotARepository; an empty value fails
the same way, as in Git. <git-dir>/objects is not consulted unless it is listed in
Self::git_alternate_object_directories or in this directory’s info/alternates.
git_prefix: Option<String>When set, overrides the repository-relative cwd prefix derived from cwd.
git_config_nosystem: Option<String>Override for GIT_CONFIG_NOSYSTEM when set (see Git environment variable of the same name).
git_config_system: Option<String>Override for GIT_CONFIG_SYSTEM when set (see Git environment variable of the same name).
git_config_global: Option<String>Override for GIT_CONFIG_GLOBAL when set (see Git environment variable of the same name).
git_config: Option<String>Override for GIT_CONFIG when set (see Git environment variable of the same name).
git_config_parameters: Option<String>Override for GIT_CONFIG_PARAMETERS when set (see Git environment variable of the same name).
git_config_count: Option<String>Override for GIT_CONFIG_COUNT when set (see Git environment variable of the same name).
git_config_pairs: Vec<(String, String)>Pairs from GIT_CONFIG_KEY_n / GIT_CONFIG_VALUE_n when GIT_CONFIG_COUNT is set.
home: Option<OsString>Override for HOME when set (see Git environment variable of the same name).
xdg_config_home: Option<String>Override for XDG_CONFIG_HOME when set (see Git environment variable of the same name).
userprofile: Option<OsString>Override for USERPROFILE when set (see Git environment variable of the same name).
homedrive: Option<OsString>Override for HOMEDRIVE when set (see Git environment variable of the same name).
homepath: Option<OsString>Override for HOMEPATH when set (see Git environment variable of the same name).
git_install_root: Option<OsString>Override for GIT_INSTALL_ROOT when set (see Git environment variable of the same name).
git_exec_path: Option<OsString>Override for GIT_EXEC_PATH when set (see Git environment variable of the same name).
pwd: Option<String>$PWD when set (symlink-preserving absolute path for include matching).
git_test_assume_different_owner: Option<String>Override for GIT_TEST_ASSUME_DIFFERENT_OWNER when set (see Git environment variable of the same name).
grit_debug_safe_dir: boolWhen true, relaxes safe-directory checks for debugging.
git_trace_setup: Option<String>Override for GIT_TRACE_SETUP when set (see Git environment variable of the same name).
git_trace2_perf: Option<String>Override for GIT_TRACE2_PERF when set (see Git environment variable of the same name).
grit_invocation_cwd: Option<String>Original working directory of the grit invocation (for messages).
sudo_uid: Option<String>Override for SUDO_UID when set (see Git environment variable of the same name).
git_test_utf8_nfd_to_nfc: Option<String>Override for GIT_TEST_UTF8_NFD_TO_NFC when set (see Git environment variable of the same name).
git_test_no_write_rev_index: Option<String>Override for GIT_TEST_NO_WRITE_REV_INDEX when set (see Git environment variable of the same name).
git_test_reftable_autocompaction: Option<String>Test knob: when "false", reftable auto-compaction is disabled (CLI captures at open).
Override for GIT_AUTHOR_NAME when set (see Git environment variable of the same name).
Override for GIT_AUTHOR_EMAIL when set (see Git environment variable of the same name).
Override for GIT_AUTHOR_DATE when set (see Git environment variable of the same name).
git_committer_name: Option<String>Override for GIT_COMMITTER_NAME when set (see Git environment variable of the same name).
git_committer_email: Option<String>Override for GIT_COMMITTER_EMAIL when set (see Git environment variable of the same name).
git_committer_date: Option<String>Override for GIT_COMMITTER_DATE when set (see Git environment variable of the same name).
tz: Option<String>Timezone for local date formatting (TZ).
user: Option<String>Override for USER when set (see Git environment variable of the same name).
username: Option<String>Override for USERNAME when set (see Git environment variable of the same name).
program_files: Option<String>Windows %ProgramFiles% (for Git for Windows system config discovery).
program_files_x86: Option<String>Windows %ProgramFiles(x86)%.
Implementations§
Source§impl Environment
impl Environment
Sourcepub fn is_fetch_options_default(&self) -> bool
pub fn is_fetch_options_default(&self) -> bool
Whether this snapshot matches Self::empty, the default
crate::transfer::FetchOptions::environment value.
SSH transport uses the repository Environment when fetch options still
carry this sentinel so FetchOptions::default() does not mask GIT_SSH_*
stored on the repository handle.
Sourcepub fn from_vars(
vars: impl IntoIterator<Item = (OsString, OsString)>,
cwd: PathBuf,
) -> Self
pub fn from_vars( vars: impl IntoIterator<Item = (OsString, OsString)>, cwd: PathBuf, ) -> Self
Parse known discovery/config variables from vars without reading the process environment.
Unknown keys from vars are retained for later lookup via Self::var / Self::var_os.
GIT_CONFIG_COUNT expands into Self::git_config_pairs.
Sourcepub fn git_now_date_override(&self) -> Option<i64>
pub fn git_now_date_override(&self) -> Option<i64>
Parsed epoch from GIT_AUTHOR_DATE / GIT_COMMITTER_DATE when set.
Sourcepub fn reftable_autocompaction_enabled(&self) -> bool
pub fn reftable_autocompaction_enabled(&self) -> bool
Whether reftable auto-compaction is enabled for this process snapshot.
Defaults to true. Set GIT_TEST_REFTABLE_AUTOCOMPACTION=false at the CLI
boundary to disable (see site global-options docs).
Sourcepub fn test_assume_different_owner(&self) -> bool
pub fn test_assume_different_owner(&self) -> bool
Whether GIT_TEST_ASSUME_DIFFERENT_OWNER is enabled.
Sourcepub fn with_git_dir(self, path: impl AsRef<Path>) -> Self
pub fn with_git_dir(self, path: impl AsRef<Path>) -> Self
Use path as the repository directory, like setting GIT_DIR.
A relative path is resolved against Self::cwd now, so the stored value stays
correct when it is exported to subprocesses that run in another directory.
§Parameters
path: the.gitdirectory (or gitfile) to open instead of discovering one.
§Returns
This environment with Self::git_dir set.
Sourcepub fn with_work_tree(self, path: impl AsRef<Path>) -> Self
pub fn with_work_tree(self, path: impl AsRef<Path>) -> Self
Use path as the work tree root, like setting GIT_WORK_TREE.
A relative path is resolved against Self::cwd now, as in Self::with_git_dir.
§Parameters
path: the directory to treat as the top of the work tree.
§Returns
This environment with Self::git_work_tree set.
Sourcepub fn push_config_override(&mut self, config_override: &ConfigOverride)
pub fn push_config_override(&mut self, config_override: &ConfigOverride)
Append a command-line configuration override (git -c key=value).
The override is added to Self::git_config_parameters in the quoted
'key'='value' form ('key'= for a bare key) that Git itself writes to
GIT_CONFIG_PARAMETERS for git -c, so it is read by
ConfigSet::load with command-line scope and is
inherited by subprocesses through Self::subprocess_environment. Later overrides win
over earlier ones, over GIT_CONFIG_COUNT pairs, and over every config file.
§Parameters
config_override: the validated key and optional value to add.
Sourcepub fn capture_process() -> Self
pub fn capture_process() -> Self
Snapshot discovery/config variables from the current process (CLI and legacy call sites).
Sourcepub fn config_fingerprint(&self) -> Option<Vec<(String, Option<String>)>>
pub fn config_fingerprint(&self) -> Option<Vec<(String, Option<String>)>>
Fingerprint of config-related fields for cascade cache keys (mirrors prior env-var scan).
Sourcepub fn var(&self, key: &str) -> Option<String>
pub fn var(&self, key: &str) -> Option<String>
Return a string env var from this environment, if present and UTF-8.
Sourcepub fn discovery_cwd(&self) -> PathBuf
pub fn discovery_cwd(&self) -> PathBuf
Resolve cwd for discovery: canonicalize when possible without env::current_dir.
Sourcepub fn subprocess_environment(&self) -> Vec<(OsString, OsString)>
pub fn subprocess_environment(&self) -> Vec<(OsString, OsString)>
Variables exported to hook/filter subprocesses (no process inheritance).
Typed fields are authoritative for the variables they model (clearing
Self::git_dir removes GIT_DIR even when the original snapshot had it). Every other
variable captured by Self::from_vars (PATH, SystemRoot, LANG, …) is passed
through unchanged, as Git does for hooks, so child processes can find their tools.
Sourcepub fn home_dir(&self) -> Option<PathBuf>
pub fn home_dir(&self) -> Option<PathBuf>
User home directory using the same resolution as Git config loading.
Sourcepub fn default_xdg_config_git_file(&self, name: &str) -> Option<PathBuf>
pub fn default_xdg_config_git_file(&self, name: &str) -> Option<PathBuf>
Default path for $XDG_CONFIG_HOME/git/{name} or $HOME/.config/git/{name}.
Used for Git’s implicit global excludes (ignore) and attributes (attributes) files
when core.excludesfile / core.attributesfile are unset.