void test_config_global__open_global(void) { git_config *cfg, *global, *selected, *dummy; cl_git_pass(git_config_open_default(&cfg)); cl_git_pass(git_config_open_level(&global, cfg, GIT_CONFIG_LEVEL_GLOBAL)); cl_git_fail(git_config_open_level(&dummy, cfg, GIT_CONFIG_LEVEL_XDG)); cl_git_pass(git_config_open_global(&selected, cfg)); git_config_free(selected); git_config_free(global); git_config_free(cfg); }
/** * ggit_config_new_default: * @error: a #GError for error reporting, or %NULL. * * 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. * * Returns: (transfer none): A #GgitConfig * **/ GgitConfig * ggit_config_new_default (GError **error) { git_config *config; gint ret; ret = git_config_open_default (&config); if (ret != GIT_OK) { _ggit_error_set (error, ret); return NULL; } else { return _ggit_config_wrap (config); } }
void test_config_global__open_programdata(void) { git_config *cfg; git_repository *repo; git_buf config_path = GIT_BUF_INIT; git_buf var_contents = GIT_BUF_INIT; if (cl_is_env_set("GITTEST_INVASIVE_FS_STRUCTURE")) cl_skip(); cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_PROGRAMDATA, &config_path)); if (!git_path_isdir(config_path.ptr)) cl_git_pass(p_mkdir(config_path.ptr, 0777)); cl_git_pass(git_buf_puts(&config_path, "/config")); cl_git_pass(git_config_open_ondisk(&cfg, config_path.ptr)); cl_git_pass(git_config_set_string(cfg, "programdata.var", "even higher level")); git_buf_free(&config_path); git_config_free(cfg); git_config_open_default(&cfg); cl_git_pass(git_config_get_string_buf(&var_contents, cfg, "programdata.var")); cl_assert_equal_s("even higher level", var_contents.ptr); git_config_free(cfg); git_buf_free(&var_contents); cl_git_pass(git_repository_init(&repo, "./foo.git", true)); cl_git_pass(git_repository_config(&cfg, repo)); cl_git_pass(git_config_get_string_buf(&var_contents, cfg, "programdata.var")); cl_assert_equal_s("even higher level", var_contents.ptr); git_config_free(cfg); git_buf_free(&var_contents); git_repository_free(repo); cl_fixture_cleanup("./foo.git"); }
void test_config_global__open_xdg(void) { git_config *cfg, *xdg, *selected; const char *str = "teststring"; const char *key = "this.variable"; git_buf buf = {0}; cl_git_mkfile("xdg/git/config", "# XDG config\n[core]\n test = 1\n"); cl_git_pass(git_config_open_default(&cfg)); cl_git_pass(git_config_open_level(&xdg, cfg, GIT_CONFIG_LEVEL_XDG)); cl_git_pass(git_config_open_global(&selected, cfg)); cl_git_pass(git_config_set_string(xdg, key, str)); cl_git_pass(git_config_get_string_buf(&buf, selected, key)); cl_assert_equal_s(str, buf.ptr); git_buf_free(&buf); git_config_free(selected); git_config_free(xdg); git_config_free(cfg); }
int cmd_config(git_repository *repo, int argc, char **argv) { int rc = EXIT_FAILURE; int err = 0; git_config *config = NULL; struct cli cli = {0}; if (!parse_cli(argc, argv, &cli, POF_VALIDATE)) { return GIT_ERROR; } if (usage_cli(argv[0], &cli)) { return GIT_OK; } if (repo && !cli.global) { if (!cli.value) { if ((err = git_repository_config_snapshot(&config,repo)) != GIT_OK) goto out; } else { if ((err = git_repository_config(&config,repo)) != GIT_OK) goto out; } } else { #ifdef __amigaos4__ FILE *f = fopen("ENVARC:gitconfig", "rb"); if (!f) { if ((f = fopen("ENVARC:gitconfig", "wb"))) { fprintf(stderr, "Created global config in ENVARC:gitconfig\n"); } else { fprintf(stderr, "Unable to create ENVARC:gitconfig\n"); } } if (f) { fclose(f); } #endif if ((err = git_config_open_default(&config))) goto out; if (!cli.value) { git_config *snapshot; if ((err = git_config_snapshot(&snapshot, config))) goto out; git_config_free(config); config = snapshot; } } if (!cli.name) { fprintf(stderr,"Invalid or not supported command line format!\n"); goto out; } if (cli.value) { if ((err = git_config_set_string(config, cli.name, cli.value))) goto out; } else { const char *val; if ((err = git_config_get_string(&val, config, cli.name)) != GIT_OK) goto out; printf("%s\n",val); } rc = EXIT_SUCCESS; out: if (err) libgit_error(); if (config) git_config_free(config); return rc; }