pub struct Config<'repo> { /* private fields */ }Expand description
Read merged config and update the repository-local config file.
Implementations§
Source§impl<'repo> Config<'repo>
impl<'repo> Config<'repo>
Sourcepub fn new(repo: &'repo Repository) -> Self
pub fn new(repo: &'repo Repository) -> Self
Bind config operations to repo.
Sourcepub fn repository(&self) -> &'repo Repository
pub fn repository(&self) -> &'repo Repository
Underlying repository.
Sourcepub fn snapshot(&self) -> Result<Arc<ConfigSet>>
pub fn snapshot(&self) -> Result<Arc<ConfigSet>>
Shared merged config snapshot for this repository.
§Errors
Propagates config load failures.
§Examples
use grit_lib::repo::{InitOptions, Repository};
let dir = std::env::temp_dir().join("grit-config-get-doc");
let (repo, _) = Repository::init(&dir, &InitOptions::default())?;
let _ = repo.config().get("core.repositoryformatversion")?;Sourcepub fn get(&self, key: &str) -> Result<Option<String>>
pub fn get(&self, key: &str) -> Result<Option<String>>
Look up a merged config value (system / global / local / worktree cascade).
§Errors
Propagates config load failures and crate::error::ConfigError::InvalidKey for malformed keys.
Sourcepub fn get_i64(&self, key: &str) -> Result<Option<i64>>
pub fn get_i64(&self, key: &str) -> Result<Option<i64>>
Parse an integer config value (Git k/m/g suffixes supported).
Sourcepub fn get_path(&self, key: &str) -> Result<Option<PathBuf>>
pub fn get_path(&self, key: &str) -> Result<Option<PathBuf>>
Expand a path config value using this repository’s environment.
Sourcepub fn get_color(&self, key: &str) -> Result<Option<String>>
pub fn get_color(&self, key: &str) -> Result<Option<String>>
Parse a Git color value (#rgb, normal, bold, etc.).
Sourcepub fn entries_under(&self, prefix: &str) -> Result<Vec<ConfigEntry>>
pub fn entries_under(&self, prefix: &str) -> Result<Vec<ConfigEntry>>
Entries whose canonical key starts with prefix (a full key, a section such as
remote.origin, or a section prefix ending in .).
§Errors
Config load failures, and crate::error::ConfigError when prefix is empty or
invalid.
Sourcepub fn mailmap(&self) -> Result<MailmapTable>
pub fn mailmap(&self) -> Result<MailmapTable>
The repository’s mailmap, merged in Git’s source order: .mailmap in the work tree,
then mailmap.blob (HEAD:.mailmap by default in a bare repository), then
mailmap.file.
§Errors
Config load failures and unreadable mailmap.file paths; a mailmap.blob that does
not resolve to a blob is skipped with a diagnostic.
Source§impl<'repo> Config<'repo>
impl<'repo> Config<'repo>
Sourcepub fn set(
&self,
scope: ConfigScope,
key: &str,
value: &str,
options: &ConfigWriteOptions,
) -> Result<Option<ConfigWritePreview>>
pub fn set( &self, scope: ConfigScope, key: &str, value: &str, options: &ConfigWriteOptions, ) -> Result<Option<ConfigWritePreview>>
Set key to value in the config file for scope.
Sourcepub fn add_value(
&self,
scope: ConfigScope,
key: &str,
value: &str,
options: &ConfigWriteOptions,
) -> Result<Option<ConfigWritePreview>>
pub fn add_value( &self, scope: ConfigScope, key: &str, value: &str, options: &ConfigWriteOptions, ) -> Result<Option<ConfigWritePreview>>
Append value for a multi-valued key in the config file for scope.
Sourcepub fn unset(
&self,
scope: ConfigScope,
key: &str,
options: &ConfigWriteOptions,
) -> Result<Option<ConfigWritePreview>>
pub fn unset( &self, scope: ConfigScope, key: &str, options: &ConfigWriteOptions, ) -> Result<Option<ConfigWritePreview>>
Remove the last value for key in the config file for scope.
Sourcepub fn unset_all(
&self,
scope: ConfigScope,
key: &str,
options: &ConfigWriteOptions,
) -> Result<(usize, Option<ConfigWritePreview>)>
pub fn unset_all( &self, scope: ConfigScope, key: &str, options: &ConfigWriteOptions, ) -> Result<(usize, Option<ConfigWritePreview>)>
Remove every value for key in the config file for scope.
Sourcepub fn rename_section(
&self,
scope: ConfigScope,
old_name: &str,
new_name: &str,
options: &ConfigWriteOptions,
) -> Result<Option<ConfigWritePreview>>
pub fn rename_section( &self, scope: ConfigScope, old_name: &str, new_name: &str, options: &ConfigWriteOptions, ) -> Result<Option<ConfigWritePreview>>
Rename a section in the config file for scope.
Sourcepub fn remove_section(
&self,
scope: ConfigScope,
section: &str,
options: &ConfigWriteOptions,
) -> Result<Option<ConfigWritePreview>>
pub fn remove_section( &self, scope: ConfigScope, section: &str, options: &ConfigWriteOptions, ) -> Result<Option<ConfigWritePreview>>
Remove an entire section from the config file for scope.