Configuration in grit-lib follows Git’s cascade (system, global, local, worktree, and environment overrides). Use Repository::config for reads and for writes that target a scope in an open repository. For global, system, or -f file edits outside a repository, use ConfigEditor.
Loading outside a handle
ConfigSet::load parses the cascade from disk given an Environment and optional git directory. The library does not read std::env during load — embedders pass variables explicitly (see Embedding and Repository).
Typed values
ConfigSet::get_bool and ConfigSet::get_i64 return None for an unset key. A value of the wrong type is a ConfigError::InvalidValue carrying the key and a ConfigValueError that says what was wrong: not a boolean, an empty or malformed integer, an integer that overflows i64 once its k/m/g suffix is applied, or a bad color. get_bool(key).transpose()? reads an optional boolean and propagates a bad value as grit_lib::error::Error::Config. The key-less parsers parse_bool, parse_i64 and parse_color return the bare ConfigValueError; call for_key on it to attach the key.
For a setting with a Git default, apply it to the unset case: config.get_bool("commit.autoStage")?.unwrap_or(true). The core booleans that many operations consult have accessors carrying Git's default: ignore_case and precompose_unicode (both false), and preload_index and file_mode (both true).
Errors
Every config failure is a specific ConfigError variant with the offending key or value in its fields, so callers match on the variant instead of the message. For example, canonical_key returns ConfigError::InvalidKey with an InvalidKeyReason naming the malformed part. Bad GIT_CONFIG_COUNT or GIT_CONFIG_PARAMETERS input is InvalidEnvironmentCount, MissingEnvironmentKey or MalformedConfigParameters. A value outside a key's fixed word list (protocol.version, gpg.format) is UnknownValue, and a --local or --worktree location without a repository is RepositoryRequired. ConfigSet::get_regexp returns ConfigError::InvalidPattern when the pattern is not valid regex. validate_repo_config returns ConfigError::UnsupportedRepositoryFormatVersion when core.repositoryformatversion is not supported. Submodule git-dir layout problems are not config errors. They are reported as Error::Submodule with a SubmoduleError.
Writes
Pass a ConfigScope (Local, Worktree, Global, or System) and ConfigWriteOptions to Config::set, Config::add_value, Config::unset, Config::unset_all, Config::rename_section, or Config::remove_section. Successful writes reload the in-memory snapshot on the open Repository. ConfigWriteOptions carries dry-run mode, optional --type canonicalization, Git-style replace-all with an optional value pattern, and unset value patterns instead of bare boolean flags.
title: Config summary: Merged config reads and scoped writes through Repository::config and ConfigEditor.
Configuration in grit-lib follows Git’s cascade (system, global, local, worktree, and environment overrides). Use Repository::config for reads and for writes that target a scope in an open repository. For global, system, or -f file edits outside a repository, use ConfigEditor.
Loading outside a handle
ConfigSet::load parses the cascade from disk given an Environment and optional git directory. The library does not read std::env during load — embedders pass variables explicitly (see Embedding and Repository).
Typed values
ConfigSet::get_bool and ConfigSet::get_i64 return None for an unset key. A value of the wrong type is a ConfigError::InvalidValue carrying the key and a ConfigValueError that says what was wrong: not a boolean, an empty or malformed integer, an integer that overflows i64 once its k/m/g suffix is applied, or a bad color. get_bool(key).transpose()? reads an optional boolean and propagates a bad value as grit_lib::error::Error::Config. The key-less parsers parse_bool, parse_i64 and parse_color return the bare ConfigValueError; call for_key on it to attach the key.
For a setting with a Git default, apply it to the unset case: config.get_bool("commit.autoStage")?.unwrap_or(true). The core booleans that many operations consult have accessors carrying Git's default: ignore_case and precompose_unicode (both false), and preload_index and file_mode (both true).
Errors
Every config failure is a specific ConfigError variant with the offending key or value in its fields, so callers match on the variant instead of the message. For example, canonical_key returns ConfigError::InvalidKey with an InvalidKeyReason naming the malformed part. Bad GIT_CONFIG_COUNT or GIT_CONFIG_PARAMETERS input is InvalidEnvironmentCount, MissingEnvironmentKey or MalformedConfigParameters. A value outside a key's fixed word list (protocol.version, gpg.format) is UnknownValue, and a --local or --worktree location without a repository is RepositoryRequired. Submodule git-dir layout problems are not config errors. They are reported as Error::Submodule with a SubmoduleError.
Writes
Pass a ConfigScope (Local, Worktree, Global, or System) and ConfigWriteOptions to Config::set, Config::add_value, Config::unset, Config::unset_all, Config::rename_section, or Config::remove_section. Successful writes reload the in-memory snapshot on the open Repository. ConfigWriteOptions carries dry-run mode, optional --type canonicalization, Git-style replace-all with an optional value pattern, and unset value patterns instead of bare boolean flags.
Without an open Repository, ConfigEditor::global, ConfigEditor::system, or ConfigEditor::open edit one file. For local or worktree config tied to a path you discover yourself, call Repository::discover (or Repository::open when you already know the git directory) and use Repository::config with the right ConfigScope (Local or Worktree). The grit config command follows the same split: it edits with ConfigEditor when there is no repository, and Repository::config when one is open.
Writes go through config.lock and an atomic rename and keep the file's permission bits. Like Git, they do not fsync the file, so a crash may lose the update, but readers never see a partial file.