class

Git2::Config

Inherits Iterable < Reference < Object

Constructors

empty

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.

Source
open_default

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.

Source
open_global(config : Config) : Config

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.

Source
open_level(parent : Config, level : GitConfigLevelT) : Config

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.

Source
open_ondisk(path : Path) : Config

Create a new config instance containing a single on-disk file

This method is a simple utility wrapper for the following: Config.empty, Config.add_file_ondisk

Source

Class methods

add_file_ondisk(config : Config, path : Path, level : GitConfigLevelT, repo : Repository | Nil = nil, force = false) : Nil

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

Source
find_global

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

Source
find_programdata

Locate the path to the configuration file in ProgramData

Look for the file in %PROGRAMDATA% used by portable git.

Source
find_system

Locate the path to the system configuration file

If /etc/gitconfig doesn't exist, it will look for %PROGRAMFILES%.

Source
find_xdg

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.

Source
parse(value : String, _type : Bool.class) : Bool

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.

Source
parse(value : String, _type : Int32.class) : Int32

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.

Source
parse(value : String, _type : Int64.class) : Int64

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.

Source
parse(value : String, _type : Path.class) : Path

Parse string as Path

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

If the value does not begin with a tilde, the input will be returned.

Source

Instance methods

[](name : String, _type : Bool.class) : Bool

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.

Source
[](name : String, _type : Int32.class) : Int32

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.

Source
[](name : String, _type : Int64.class) : Int64

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.

Source
[](name : String, _type : String.class) : String

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.

Source
[](name : String, _type : Path.class) : Path

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.

Source
[](name : String, _type : ConfigEntry.class) : ConfigEntry

Get the ConfigEntry of a config variable

Source
[](name : String) : String

Get the value of a string config variable or raises

Source
[]=(name : String, value : String) : Nil

Set the value of a string config variable in the config file with the highest level (usually the local one)

Source
[]=(name : String, value : Bool) : Nil

Set the value of a boolean config variable in the config file with the highest level (usually the local one)

Source
[]=(name : String, value : Int32) : Nil

Set the value of an integer config variable in the config file with the highest level (usually the local one)

Source
[]=(name : String, value : Int64) : Nil

Set the value of a long integer config variable in the config file with the highest level (usually the local one)

Source
[]?(name : String) : String | Nil

Get the value of a string config variable or returns nil

Source
add_file_ondisk(path : Path, level : GitConfigLevelT, repo : Repository | Nil = nil, force = false) : Nil

See Config.add_file_ondisk

Source
delete(name : String) : Nil

Delete a config variable from the config file with the highest level (usually the local one)

Source
delete_multivar(name : String, regex : Regex) : Nil

Deletes one or several entries from a multivar in the local config file

The regex is applied case-sensitively on the value.

Source
each(regex : Regex)

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
Source
each(name : String, regex : Regex | Nil = nil)

Returns an iterator over each value of a multivar

Source
each

Returns an iterator over all the config variables

Source
finalize
Source
foreach

Perform an operation on each config variable

Source
foreach_match(regex : Regex, &block : ConfigEntry -> ) : Nil

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
Source
get_multivar_foreach(name : String, regex : Regex | Nil = nil, &block : ConfigEntry -> ) : Nil
Source
open_global

See Config.open_global

Source
open_level(level : GitConfigLevelT) : Config

See Config.open_level

Source
set_multivar(name : String, regex : Regex, value : String) : Nil

Set a multivar in the local config file

The regex is applied case-sensitively on the value.

Source
snapshot

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

Source
to_unsafe
Source