On this page:
git_  config_  add_  backend
git_  config_  add_  file_  ondisk
git_  config_  backend_  foreach_  match
git_  config_  delete_  entry
git_  config_  delete_  multivar
git_  config_  entry_  free
git_  config_  find_  global
git_  config_  find_  programdata
git_  config_  find_  system
git_  config_  find_  xdg
git_  config_  foreach
git_  config_  foreach_  match
git_  config_  free
git_  config_  get_  bool
git_  config_  get_  entry
git_  config_  get_  mapped
git_  config_  get_  multivar_  foreach
git_  config_  get_  path
git_  config_  get_  string
git_  config_  get_  string_  buf
git_  config_  init_  backend
git_  config_  iterator_  free
git_  config_  iterator_  glob_  new
git_  config_  iterator_  new
git_  config_  lock
git_  config_  lookup_  map_  value
git_  config_  multivar_  iterator_  new
git_  config_  new
git_  config_  next
git_  config_  open_  default
git_  config_  open_  global
git_  config_  open_  level
git_  config_  open_  ondisk
git_  config_  parse_  bool
git_  config_  parse_  path
git_  config_  set_  bool
git_  config_  set_  multivar
git_  config_  set_  string
git_  config_  snapshot
8.12

10 Config🔗ℹ

 (require libgit2/include/config) package: libgit2

procedure

(git_config_add_backend cfg file level force)  integer?

  cfg : config?
  file : config_backend?
  level : git_config_level_t
  force : boolean?
Add a generic config file instance to an existing config

Note that the configuration object will free the file automatically.

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

procedure

(git_config_add_file_ondisk cfg    
  path    
  level    
  force)  integer?
  cfg : config?
  path : string?
  level : git_config_level_t
  force : boolean?
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.

Note that the configuration object will free the file automatically.

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

procedure

(git_config_backend_foreach_match backend    
  regexp    
  callback    
  payload)  integer?
  backend : config_backend?
  regexp : string?
  callback : git_config_foreach_cb
  payload : bytes?
Perform an operation on each config variable in given config backend matching a regular expression.

This behaviors like git_config_foreach_match except instead of all config entries it just enumerates through the given backend entry.

procedure

(git_config_delete_entry cfg name)  integer?

  cfg : config?
  name : string?
Delete a config variable from the config file with the highest level (usually the local one).

procedure

(git_config_delete_multivar cfg name regexp)  integer?

  cfg : config?
  name : string?
  regexp : string?
Deletes one or several entries from a multivar in the local config file.

procedure

(git_config_entry_free entry)  void?

  entry : config_entry?
Free a config entry

procedure

(git_config_find_global out)  integer?

  out : buf?
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. The returned path may be used on any git_config call to load the global configuration file.

This method will not guess the path to the xdg compatible config file (.config/git/config).

procedure

(git_config_find_programdata out)  integer?

  out : buf?
Locate the path to the configuration file in ProgramData

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

procedure

(git_config_find_system out)  integer?

  out : buf?
Locate the path to the system configuration file

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

procedure

(git_config_find_xdg out)  integer?

  out : buf?
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. The returned path may be used on any git_config call to load the xdg compatible configuration file.

procedure

(git_config_foreach cfg callback payload)  integer?

  cfg : config?
  callback : git_config_foreach_cb
  payload : bytes?
Perform an operation on each config variable.

The callback receives the normalized name and value of each variable in the config backend, and the data pointer passed to this function. If the callback returns a non-zero value, the function stops iterating and returns that value to the caller.

The pointers passed to the callback are only valid as long as the iteration is ongoing.

procedure

(git_config_foreach_match cfg    
  regexp    
  callback    
  payload)  integer?
  cfg : config?
  regexp : string?
  callback : git_config_foreach_cb
  payload : bytes?
Perform an operation on each config variable matching a regular expression.

This behaviors like git_config_foreach with an additional filter of a regular expression that filters which config keys are passed to the callback.

The pointers passed to the callback are only valid as long as the iteration is ongoing.

procedure

(git_config_free cfg)  void?

  cfg : config?
Free the configuration and its associated memory and files

procedure

(git_config_get_bool out cfg name)  integer?

  out : boolean?
  cfg : config?
  name : string?
Get the value of a boolean config variable.

This function uses the usual C convention of 0 being false and anything else true.

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.

procedure

(git_config_get_entry cfg name)  config_entry?

  cfg : config?
  name : string?
Get the git_config_entry of a config variable.

Free the git_config_entry after use with git_config_entry_free().

git_config_get_int32(int32_t *out, const git_config *cfg, const char *name)

Get the value of an 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.

git_config_get_int64(int64_t *out, const git_config *cfg, const char *name)

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.

procedure

(git_config_get_mapped out    
  cfg    
  name    
  maps    
  map_n)  integer?
  out : boolean?
  cfg : config?
  name : string?
  maps : git_cvar_map?
  map_n : integer?
Query the value of a config variable and return it mapped to an integer constant.

This is a helper method to easily map different possible values to a variable to integer constants that easily identify them.

A mapping array looks as follows:

git_cvar_map autocrlf_mapping[] = { {GIT_CVAR_FALSE, NULL, GIT_AUTO_CRLF_FALSE}, {GIT_CVAR_TRUE, NULL, GIT_AUTO_CRLF_TRUE}, {GIT_CVAR_STRING, "input", GIT_AUTO_CRLF_INPUT}, {GIT_CVAR_STRING, "default", GIT_AUTO_CRLF_DEFAULT}}; On any "false" value for the variable (e.g. "false", "FALSE", "no"), the mapping will store GIT_AUTO_CRLF_FALSE in the out parameter.

The same thing applies for any "true" value such as "true", "yes" or "1", storing the GIT_AUTO_CRLF_TRUE variable.

Otherwise, if the value matches the string "input" (with case insensitive comparison), the given constant will be stored in out, and likewise for "default".

If not a single match can be made to store in out, an error code will be returned.

procedure

(git_config_get_multivar_foreach cfg    
  name    
  regexp    
  callback    
  payload)  integer?
  cfg : config?
  name : string?
  regexp : string?
  callback : git_config_foreach_cb
  payload : ?
Get each value of a multivar in a foreach callback

The callback will be called on each variable found

procedure

(git_config_get_path out cfg name)  integer?

  out : buf?
  cfg : config?
  name : string?
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.

procedure

(git_config_get_string out cfg name)  integer?

  out : string?
  cfg : config?
  name : string?
Get the value of a string config variable.

This function can only be used on snapshot config objects. The string is owned by the config and should not be freed by the user. The pointer will be valid until the config is freed.

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.

procedure

(git_config_get_string_buf out cfg name)  integer?

  out : buf?
  cfg : config?
  name : string?
Get the value of a string config variable.

The value of the config will be copied into the buffer.

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.

procedure

(git_config_init_backend backend int)  integer?

  backend : config_backend?
  int : integer?
Initializes a git_config_backend with default values. Equivalent to creating an instance with GIT_CONFIG_BACKEND_INIT.

procedure

(git_config_iterator_free iter)  void?

  iter : config_iterator?
Free a config iterator

procedure

(git_config_iterator_glob_new cfg regexp)  config_iterator?

  cfg : config?
  regexp : string?
Iterate over all the config variables whose name matches a pattern

Use git_config_next to advance the iteration and git_config_iterator_free when done.

procedure

(git_config_iterator_new cfg)  config_iterator?

  cfg : config?
Iterate over all the config variables

Use git_config_next to advance the iteration and git_config_iterator_free when done.

procedure

(git_config_lock cfg)  transaction?

  cfg : config?
Lock the backend with the highest priority

Locking disallows anybody else from writing to that backend. Any updates made after locking will not be visible to a reader until the file is unlocked.

You can apply the changes by calling git_transaction_commit() before freeing the transaction. Either of these actions will unlock the config.

procedure

(git_config_lookup_map_value out    
  maps    
  map_n    
  value)  integer?
  out : boolean?
  maps : git_cvar_map?
  map_n : size_t
  value : string?
Maps a string value to an integer constant

procedure

(git_config_multivar_iterator_new cfg    
  name    
  regexp)  config_iterator?
  cfg : config?
  name : string?
  regexp : string?
Get each value of a multivar

procedure

(git_config_new)  config?

Allocate a new configuration object

This object is empty, so you have to add a file to it before you can do anything with it.

procedure

(git_config_next iter)  config_entry?

  iter : config_iterator?
Return the current entry and advance the iterator

The pointers returned by this function are valid until the iterator is freed.

procedure

(git_config_open_default)  config?

Open the global, XDG and system configuration 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.

procedure

(git_config_open_global config)  config?

  config : config?
Open the global/XDG configuration file according to git’s rules

Git allows you to store your global configuration at $HOME/.config or $XDG_CONFIG_HOME/git/config. For backwards compatability, the XDG file shouldn’t be used unless the use has created it explicitly. With this function you’ll open the correct one to write to.

procedure

(git_config_open_level parent level)  config?

  parent : config?
  level : git_config_level_t
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.

procedure

(git_config_open_ondisk path)  config?

  path : string?
Create a new config instance containing a single on-disk file

This method is a simple utility wrapper for the following sequence of calls: - git_config_new - git_config_add_file_ondisk

procedure

(git_config_parse_bool out value)  integer?

  out : boolean?
  value : string?
Parse a string value as a 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

git_config_parse_int32(int32_t *out, const char *value)

Parse a string value as an int32.

An optional value suffix of ’k’, ’m’, or ’g’ will cause the value to be multiplied by 1024, 1048576, or 1073741824 prior to output.

git_config_parse_int64(int64_t *out, const char *value)

Parse a string value as an int64.

An optional value suffix of ’k’, ’m’, or ’g’ will cause the value to be multiplied by 1024, 1048576, or 1073741824 prior to output.

procedure

(git_config_parse_path out value)  integer?

  out : buf?
  value : string?
Parse a string value as a 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.

procedure

(git_config_set_bool cfg name value)  integer?

  cfg : config?
  name : string?
  value : boolean?
Set the value of a boolean config variable in the config file with the highest level (usually the local one).

git_config_set_int32(git_config *cfg, const char *name, int32_t value)

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

git_config_set_int64(git_config *cfg, const char *name, int64_t value)

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

procedure

(git_config_set_multivar cfg    
  name    
  regexp    
  value)  integer?
  cfg : config?
  name : string?
  regexp : string?
  value : string?
Set a multivar in the local config file.

procedure

(git_config_set_string cfg name value)  integer?

  cfg : config?
  name : string?
  value : string?
Set the value of a string config variable in the config file with the highest level (usually the local one).

A copy of the string is made and the user is free to use it afterwards.

procedure

(git_config_snapshot config)  config?

  config : config?
Create a snapshot of the configuration

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

The string returned when querying such a config object is valid until it is freed.