Git2::Config
Constructors
Allocate a new config object
This object is empty, so you have to add a file to it before you can do anything with it.
Open the global, XDG and system config files
Utility wrapper that finds the global, XDG and system configuration files and opens them into a single prioritized config object that can be used when accessing default config data outside a repository.
Open the global/XDG config file according to git's rules
Git allows you to store your global configuration at $HOME/.gitconfig
or $XDG_CONFIG_HOME/git/config.
For backwards compatability, the XDG file shouldn't be used unless the user has created it explicitly. This method opens the correct one to write to.
Build a single-level focused config object from a multi-level one
The returned config object can be used to perform get/set/delete operations on a single specific level.
Getting several times the same level from the same parent multi-level config will return different config instances, but containing the same config_file instance.
Class methods
Add an on-disk config file instance to an existing config
The on-disk file pointed at by path will be opened and parsed;
it's expected to be a native Git config file following the
default Git config syntax (see man git-config).
If the file does not exist, the file will still be added and it will be created the first time we write to it.
Further queries on this config object will access each of the config file instances in order (instances with a higher priority level will be accessed first).
Locate the path to the global configuration file
The user or global configuration file is usually located in $HOME/.gitconfig.
This method will try to guess the full path to that file, if the file exists.
This method will not guess the path to the xdg compatible config file (.config/git/config).
Locate the path to the configuration file in ProgramData
Look for the file in %PROGRAMDATA% used by portable git.
Locate the path to the system configuration file
If /etc/gitconfig doesn't exist, it will look for %PROGRAMFILES%.
Locate the path to the global xdg compatible configuration file
The xdg compatible configuration file is usually located in $HOME/.config/git/config.
This method will try to guess the full path to that file, if the file exists.
Parse string as Bool
Valid values for true are: 'true', 'yes', 'on', 1 or any number different from 0.
Valid values for false are: 'false', 'no', 'off', 0.
Parse string as Int32
An optional value suffix of 'k', 'm', or 'g' will cause the value to be multiplied by 1_024, 1_048_576, or 1_073_741_824 prior to output.
Parse string as Int64
An optional value suffix of 'k', 'm', or 'g' will cause the value to be multiplied by 1_024, 1_048_576, or 1_073_741_824 prior to output.
Instance methods
Get the value of a boolean config variable
All config files will be looked into, in the order of their defined level. A higher level means a higher priority. The first occurrence of the variable will be returned here.
Get the value of a integer config variable
All config files will be looked into, in the order of their defined level. A higher level means a higher priority. The first occurrence of the variable will be returned here.
Get the value of a long integer config variable
All config files will be looked into, in the order of their defined level. A higher level means a higher priority. The first occurrence of the variable will be returned here.
Get the value of a string config variable
All config files will be looked into, in the order of their defined level. A higher level means a higher priority. The first occurrence of the variable will be returned here.
Get the value of a path config variable
A leading '~' will be expanded to the global search path
(which defaults to the user's home directory but can be overridden
via git_libgit2_opts().
All config files will be looked into, in the order of their defined level. A higher level means a higher priority. The first occurrence of the variable will be returned here.
Get the ConfigEntry of a config variable
Set the value of a string config variable in the config file with the highest level (usually the local one)
Set the value of a boolean config variable in the config file with the highest level (usually the local one)
Set the value of an integer config variable in the config file with the highest level (usually the local one)
Set the value of a long integer config variable in the config file with the highest level (usually the local one)
See Config.add_file_ondisk
Delete a config variable from the config file with the highest level (usually the local one)
Deletes one or several entries from a multivar in the local config file
The regex is applied case-sensitively on the value.
Returns an iterator over all the config variables whose name matches a pattern
The regular expression is applied case-sensitively on the normalized form of the variable name:
- the section and variable parts are lower-cased
- the subsection is left unchanged
Returns an iterator over each value of a multivar
Perform an operation on each config variable matching a regular expression
This behaves like Config#foreach with an additional filter of a regular expression
that filters which config keys are passed to the callback.
The regular expression is applied case-sensitively on the normalized form of the variable name:
- the section and variable parts are lower-cased
- the subsection is left unchanged
Set a multivar in the local config file
The regex is applied case-sensitively on the value.
Returns a new snapshot of the config, as a new Config instance
Create a snapshot of the current state of a configuration, which allows you to look into a consistent view of the configuration for looking up complex values (e.g. a remote, submodule).