GgitConfig: libgit2-glib Reference Manual

## GgitConfig GgitConfig |

## Functions

gint | (*GgitConfigCallback) ()
gint | (*GgitConfigMatchCallback) ()
GgitConfig * | ggit_config_new ()
GgitConfig * | ggit_config_new_default ()
GgitConfig * | ggit_config_new_from_file ()
GFile * | ggit_config_find_global ()
GFile * | ggit_config_find_system ()
void | ggit_config_add_file ()
gint32 | ggit_config_get_int32 ()
gboolean | ggit_config_set_int32 ()
gint64 | ggit_config_get_int64 ()
gboolean | ggit_config_set_int64 ()
gboolean | ggit_config_get_bool ()
gboolean | ggit_config_set_bool ()
const gchar * | ggit_config_get_string ()
gboolean | ggit_config_set_string ()
gboolean | ggit_config_delete_entry ()
gboolean | ggit_config_foreach ()
gchar * | ggit_config_match ()
gboolean | ggit_config_match_foreach ()

## Types and Values

| GgitConfig
enum | GgitConfigLevel

## Object Hierarchy

        GEnum
        ╰── GgitConfigLevel
        GObject
        ╰── GgitObjectFactoryBase
            ╰── GgitNative
                ╰── GgitConfig

## Description

## Functions

### GgitConfigCallback ()

    gint
    (*GgitConfigCallback) (GgitConfigEntry *entry,
                           gpointer user_data);

The type of the callback functions for retrieving values from a GgitConfig. See `ggit_config_foreach()`.

#### Parameters

entry | a GgitConfigEntry. |
user_data | user-supplied data. | [closure]

#### Returns

0 to go for the next config value or a GgitError in case there was an error.

### GgitConfigMatchCallback ()

    gint
    (*GgitConfigMatchCallback) (GMatchInfo *match_info,
                                const gchar *value,
                                gpointer user_data);

The type of the callback functions for retrieving values from a GgitConfig using a regular expression. See `ggit_config_match_foreach()`.

#### Parameters

match_info | the match |
value | the value |
user_data | user-supplied data. | [closure]

#### Returns

0 to go for the next config value or a GgitError in case there was an error.

### ggit_config_new ()

    GgitConfig *
    ggit_config_new (void);

Create a new config. See also `ggit_config_get_default()` to get a GgitConfig representing the global, XDG and system configuration files. To get a GgitConfig for a repository use ggit_repository_get_config instead.

#### Returns

a GgitConfig.

[transfer full]

### ggit_config_new_default ()

    GgitConfig *
    ggit_config_new_default (GError **error);

Get the global, XDG and system configuration files merged into one GgitConfig with their appropriate priority levels. If an error occured trying to load the various configuration files, this function will return `NULL` and `error` will be set accordingly.

#### Parameters

error | a GError for error reporting, or `NULL`. |

#### Returns

A GgitConfig.

[transfer none]

### ggit_config_new_from_file ()

    GgitConfig *
    ggit_config_new_from_file (GFile *file,
                               GError **error);

Create a new config from a single on disk file. This is a convenience API and is exactly the same as creating an empty GgitConfig using ggit_config_new and adding the file with ggit_config_add_file. The level will be set to GGIT_CONFIG_LEVEL_LOCAL. If the config could not be loaded this function returns `NULL` and `error` will be set accordingly.

#### Parameters

file | the file to load. |
error | a GError for error reporting, or `NULL`. |

#### Returns

a GgitConfig.

[transfer full]

### ggit_config_find_global ()

    GFile *
    ggit_config_find_global (void);

Find the file representing the users global git configuration. This file is usually located at $HOME/.gitconfig. This function will try to guess the full path to that file, if the file exists. The returned file may then be used with ggit_config_new_from_file or ggit_config_add_file. This function returns `NULL` if the global config could not be found.

#### Returns

a GFile or `NULL` if the global config could not be found.

[transfer full]

### ggit_config_find_system ()

    GFile *
    ggit_config_find_system (void);

Find the file representing the systems global git configuration. This file is usually located at /etc/gitconfig on UNIX type systems or `PROGRAMFILES`%\Git\etc\gitconfig on windows. This function will try to guess the full path to that file, if the file exists. The returned file may then be used with ggit_config_new_from_file or ggit_config_add_file. This function returns `NULL` if the system config could not be found.

#### Returns

a GFile or `NULL` if the system config could not be found.

[transfer full]

### ggit_config_add_file ()

    void
    ggit_config_add_file (GgitConfig *config,
                          GFile *file,
                          GgitConfigLevel level,
                          gboolean force,
                          GError **error);

Add an on-disk config file instance to an existing config

The on-disk file pointed at by `file` 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).

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

#### Parameters

config | a GgitConfig. |
file | a GFile. |
level | a GgitConfigLevel. |
force | if a config file already exists for the given priority level, replace it. |
error | a GError for error reporting, or `NULL`. |

### ggit_config_get_int32 ()

    gint32
    ggit_config_get_int32 (GgitConfig *config,
                           const gchar *name,
                           GError **error);

Get a int32 configuration value.

#### Parameters

config | a GgitConfig. |
name | the name of the configuration value. |
error | a GError for error reporting, or `NULL`. |

#### Returns

the value.

### ggit_config_set_int32 ()

    gboolean
    ggit_config_set_int32 (GgitConfig *config,
                           const gchar *name,
                           gint32 value,
                           GError **error);

Set a int32 value.

#### Parameters

config | a GgitConfig. |
name | the name of the configuration value. |
value | the new value. |
error | a GError for error reporting, or `NULL`. |

#### Returns

`TRUE` if the value was successfully set, `FALSE` otherwise.

### ggit_config_get_int64 ()

    gint64
    ggit_config_get_int64 (GgitConfig *config,
                           const gchar *name,
                           GError **error);

Get a int64 configuration value.

#### Parameters

config | a GgitConfig. |
name | the name of the configuration value. |
error | a GError for error reporting, or `NULL`. |

#### Returns

the value.

### ggit_config_set_int64 ()

    gboolean
    ggit_config_set_int64 (GgitConfig *config,
                           const gchar *name,
                           gint64 value,
                           GError **error);

Set a int64 value.

#### Parameters

config | a GgitConfig. |
name | the name of the configuration value. |
value | the new value. |
error | a GError for error reporting, or `NULL`. |

#### Returns

`TRUE` if the value was successfully set, `FALSE` otherwise.

### ggit_config_get_bool ()

    gboolean
    ggit_config_get_bool (GgitConfig *config,
                          const gchar *name,
                          GError **error);

Get a boolean configuration value.

#### Parameters

config | a GgitConfig. |
name | the name of the configuration value. |
error | a GError for error reporting, or `NULL`. |

#### Returns

the value.

### ggit_config_set_bool ()

    gboolean
    ggit_config_set_bool (GgitConfig *config,
                          const gchar *name,
                          gboolean value,
                          GError **error);

Set a boolean value.

#### Parameters

config | a GgitConfig. |
name | the name of the configuration value. |
value | the new value. |
error | a GError for error reporting, or `NULL`. |

#### Returns

`TRUE` if the value was successfully set, `FALSE` otherwise.

### ggit_config_get_string ()

    const gchar *
    ggit_config_get_string (GgitConfig *config,
                            const gchar *name,
                            GError **error);

Get the configuration value of `name` as string.

#### Parameters

config | a GgitConfig. |
name | the name of the configuration value. |
error | a GError for error reporting, or `NULL`. |

#### Returns

the string value of `name` , or `NULL` if such a value does not exist.

[allow-none]

### ggit_config_set_string ()

    gboolean
    ggit_config_set_string (GgitConfig *config,
                            const gchar *name,
                            const gchar *value,
                            GError **error);

Set a new string value of a configuration.

#### Parameters

config | a GgitConfig. |
name | the name of the configuration value. |
value | the new value. |
error | a GError for error reporting, or `NULL`. |

#### Returns

`TRUE` if the value was successfully set, `FALSE` otherwise.

### ggit_config_delete_entry ()

    gboolean
    ggit_config_delete_entry (GgitConfig *config,
                              const gchar *name,
                              GError **error);

Delete a config variable from the config file.

#### Parameters

config | a GgitConfig. |
name | the configuration value. |
error | a GError for error reporting, or `NULL`. |

#### Returns

`TRUE` if the configuration value was deleted, `FALSE` otherwise.

### ggit_config_foreach ()

    gboolean
    ggit_config_foreach (GgitConfig *config,
                         GgitConfigCallback callback,
                         gpointer user_data,
                         GError **error);

Call `callback` for each configuration value.

#### Parameters

config | a GgitConfig. |
callback | a GgitConfigCallback. | [scope call]
user_data | the user data for `callback` . | [allow-none]
error | a GError for error reporting, or `NULL`. |

#### Returns

`TRUE` if successfull, `FALSE` otherwise

### ggit_config_match ()

    gchar *
    ggit_config_match (GgitConfig *config,
                       GRegex *regex,
                       GMatchInfo **match_info,
                       GError **error);

Matches a configuration against a regular expression. `match_info` will contain the match information if the return value is not `NULL`, otherwise `error` will be set.

#### Parameters

config | a GgitConfig. |
regex | a GRegex. |
match_info | a GMatchInfo. | [out][allow-none]
error | a GError for error reporting, or `NULL`. |

#### Returns

the value of that matched configuration.

[allow-none][transfer full]

### ggit_config_match_foreach ()

    gboolean
    ggit_config_match_foreach (GgitConfig *config,
                               GRegex *regex,
                               GgitConfigMatchCallback callback,
                               gpointer user_data,
                               GError **error);

Call `callback` for all configurations matching `regex` .

#### Parameters

config | a GgitConfig. |
regex | a GRegex. |
callback | a GgitConfigMatchCallback. | [scope call][closure user_data]
user_data | the user data for `callback` . | [closure]
error | a GError for error reporting, or `NULL`. |

#### Returns

`TRUE` if matches were successfull, `FALSE` otherwise

## Types and Values

### GgitConfig

    typedef struct _GgitConfig GgitConfig;

Represents a git configuration.

### enum GgitConfigLevel

Priority level of a config file. These priority levels correspond to the natural escalation logic (from higher to lower) when searching for config entries in git.git.

#### Members

GGIT_CONFIG_LEVEL_SYSTEM | System-wide configuration file. |
GGIT_CONFIG_LEVEL_XDG | XDG compatible configuration file (.config/git/config). |
GGIT_CONFIG_LEVEL_GLOBAL | User-specific configuration file, also called Global configuration file. |
GGIT_CONFIG_LEVEL_LOCAL | Repository specific configuration file. |
GGIT_CONFIG_LEVEL_HIGHEST | Represents the highest level of a config file. |