Get or set Git options, as git config does on the command line. Global
settings affect all of a user's Git operations (git config --global),
whereas local settings are scoped to a specific repository (git config --local). When both exist, local options always win.
| local | global | |
| get all | git_config() | git_config_global() |
| get one (local+global) | git_config_get() | git_config_get() |
| get one (local or global only) | git_config_local_get() | git_config_global_get() |
| set | git_config_set() | git_config_global_set() |
Usage
git_config(repo = ".")
git_config_global()
git_config_get(name, repo = ".")
git_config_local_get(name, repo = ".")
git_config_global_get(name)
git_config_set(name, value, add = FALSE, repo = ".")
git_config_global_set(name, value, add = FALSE)Arguments
- repo
The path to the git repository. If the directory is not a repository, parent directories are considered (see
git_find()). To disable this search, provide the filepath protected withI(). When using this parameter, always explicitly call by name (i.e.repo =) because future versions of gert may have additional parameters.- name
Name of the option to get or set
- value
Value to set. Must be a string, logical, number or
NULL(to unset).- add
if
TRUE, append a new entry fornameinstead of replacing existing one(s). Equivalent togit config --add. Only supported for string values.
Value
git_config(): adata.frameof the Git options "in force" in the context ofrepo, one row per option. Thelevelcolumn reveals whether the option is determined from global or local config.git_config_global(): adata.frame, as forgit_config(), except only for global Git options.git_config_get(): the value of the named option considering both local and global config (local wins), orNULLif unset.git_config_local_get(): as forgit_config_get(), but restricted to local (repository-level) config only.git_config_global_get(): as forgit_config_get(), but for global config only.git_config_set(),git_config_global_set(): The previous value(s) ofnamein local or global config, respectively. If this option was previously unset, returnsNULL. Returns invisibly.
Note
All entries in the name column are automatically normalised to
lowercase (see
https://libgit2.org/libgit2/#HEAD/type/git_config_entry for details).
Examples
# Set and inspect a local, custom Git option
r <- file.path(tempdir(), "gert-demo")
git_init(r)
previous <- git_config_set("aaa.bbb", "ccc", repo = r)
previous
#> NULL
git_config_local_get("aaa.bbb", repo = r)
#> [1] "ccc"
previous <- git_config_set("aaa.bbb", NULL, repo = r)
previous
#> [1] "ccc"
git_config_local_get("aaa.bbb", repo = r)
#> NULL
# Get a single named option (returns NULL if unset)
git_config_get("aaa.bbb", repo = r)
#> NULL
git_config_set("aaa.bbb", "ccc", repo = r)
git_config_get("aaa.bbb", repo = r)
#> [1] "ccc"
unlink(r, recursive = TRUE)
if (FALSE) { # \dontrun{
# Set global Git options
git_config_global_set("user.name", "Your Name")
git_config_global_set("user.email", "your@email.com")
git_config_global()
# Get a single global option (returns NULL if unset)
git_config_global_get("user.name")
git_config_global_get("gert.nonexistent")
} # }
