Skip to main content

Environment

Struct Environment 

Source
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: PathBuf

Process 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: bool

When 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: bool

When 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).

§git_author_name: Option<String>

Override for GIT_AUTHOR_NAME when set (see Git environment variable of the same name).

§git_author_email: Option<String>

Override for GIT_AUTHOR_EMAIL when set (see Git environment variable of the same name).

§git_author_date: Option<String>

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

Source

pub fn empty() -> Self

No overrides; Self::cwd is "." (canonicalized by callers when needed).

Source

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.

Source

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.

Source

pub fn git_now_date_override(&self) -> Option<i64>

Parsed epoch from GIT_AUTHOR_DATE / GIT_COMMITTER_DATE when set.

Source

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).

Source

pub fn test_assume_different_owner(&self) -> bool

Whether GIT_TEST_ASSUME_DIFFERENT_OWNER is enabled.

Source

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 .git directory (or gitfile) to open instead of discovering one.
§Returns

This environment with Self::git_dir set.

Source

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.

Source

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.
Source

pub fn capture_process() -> Self

Snapshot discovery/config variables from the current process (CLI and legacy call sites).

Source

pub fn config_fingerprint(&self) -> Option<Vec<(String, Option<String>)>>

Fingerprint of config-related fields for cascade cache keys (mirrors prior env-var scan).

Source

pub fn var(&self, key: &str) -> Option<String>

Return a string env var from this environment, if present and UTF-8.

Source

pub fn var_os(&self, key: &str) -> Option<OsString>

Var os.

Source

pub fn discovery_cwd(&self) -> PathBuf

Resolve cwd for discovery: canonicalize when possible without env::current_dir.

Source

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.

Source

pub fn home_dir(&self) -> Option<PathBuf>

User home directory using the same resolution as Git config loading.

Source

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.

Trait Implementations§

Source§

impl Clone for Environment

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Environment

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl IdentityEnv for Environment

Source§

fn var(&self, key: &str) -> Option<String>

Return a UTF-8 environment variable, if it exists and is valid Unicode.
Source§

fn var_os(&self, key: &str) -> Option<OsString>

Return a raw environment variable value, preserving non-UTF-8 bytes on Unix.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.