Configuration files
- class pygit2.Repository(path: str | bytes | None | ~pathlib.Path = None, flags: ~pygit2.enums.RepositoryOpenFlag = <RepositoryOpenFlag.DEFAULT: 0>)
- property config: Config
The configuration file for this repository.
If a the configuration hasn’t been set yet, the default config for repository will be returned, including global and system configurations (if they are available).
The Config type
- class pygit2.Config(path: str | None = None)
Git configuration management.
- __contains__(key: str | bytes) bool
- __delitem__(key: str | bytes) None
- __getitem__(key: str | bytes) str
When using the mapping interface, the value is returned as a string. In order to apply the git-config parsing rules, you can use
Config.get_bool()
orConfig.get_int()
.
- __iter__() Iterator[ConfigEntry]
Iterate over configuration entries, returning a
ConfigEntry
objects. These contain the name, level, and value of each configuration variable. Be aware that this may return multiple versions of each entry if they are set multiple times in the configuration files.
- __setitem__(key: str | bytes, value: bool | int | str | bytes) None
- add_file(path: str | Path, level: int = 0, force: int = 0) None
Add a config file instance to an existing config.
- delete_multivar(name: str | bytes, regex: str | bytes) None
Delete a multivar ‘’name’’. ‘’regexp’’ is a regular expression to indicate which values to delete.
- get_bool(key: str | bytes) bool
Look up key and parse its value as a boolean as per the git-config rules. Return a boolean value (True or False).
Truthy values are: ‘true’, 1, ‘on’ or ‘yes’. Falsy values are: ‘false’, 0, ‘off’ and ‘no’
- static get_global_config() Config
Return a <Config> object representing the global configuration file.
- get_int(key: bytes | str) int
Look up key and parse its value as an integer as per the git-config rules. Return an integer.
A value can have a suffix ‘k’, ‘m’ or ‘g’ which stand for ‘kilo’, ‘mega’ and ‘giga’ respectively.
- get_multivar(name: str | bytes, regex: str | None = None) ConfigMultivarIterator
Get each value of a multivar ‘’name’’ as a list of strings.
The optional ‘’regex’’ parameter is expected to be a regular expression to filter the variables we’re interested in.
- static get_system_config() Config
Return a <Config> object representing the system configuration file.
- static get_xdg_config() Config
Return a <Config> object representing the global configuration file.
- static parse_bool(text: str) bool
- static parse_int(text: str) int
- set_multivar(name: str | bytes, regex: str | bytes, value: str | bytes) None
Set a multivar ‘’name’’ to ‘’value’’. ‘’regexp’’ is a regular expression to indicate which values to replace.