]>
git.proxmox.com Git - libgit2.git/blob - examples/config.c
2 * libgit2 "config" example - shows how to use the config API
4 * Written by the libgit2 contributors
6 * To the extent possible under law, the author(s) have dedicated all copyright
7 * and related and neighboring rights to this software to the public domain
8 * worldwide. This software is distributed without any warranty.
10 * You should have received a copy of the CC0 Public Domain Dedication along
11 * with this software. If not, see
12 * <http://creativecommons.org/publicdomain/zero/1.0/>.
17 static int config_get(git_config
*cfg
, const char *key
)
19 git_config_entry
*entry
;
22 if ((error
= git_config_get_entry(&entry
, cfg
, key
)) < 0) {
23 if (error
!= GIT_ENOTFOUND
)
24 printf("Unable to get configuration: %s\n", git_error_last()->message
);
32 static int config_set(git_config
*cfg
, const char *key
, const char *value
)
34 if (git_config_set_string(cfg
, key
, value
) < 0) {
35 printf("Unable to set configuration: %s\n", git_error_last()->message
);
41 int lg2_config(git_repository
*repo
, int argc
, char **argv
)
46 if ((error
= git_repository_config(&cfg
, repo
)) < 0) {
47 printf("Unable to obtain repository config: %s\n", git_error_last()->message
);
52 error
= config_get(cfg
, argv
[1]);
53 } else if (argc
== 3) {
54 error
= config_set(cfg
, argv
[1], argv
[2]);
56 printf("USAGE: %s config <KEY> [<VALUE>]\n", argv
[0]);