Exemple #1
0
void test_config_refresh__delete_value(void)
{
	git_config *cfg;
	int32_t v;

	cl_git_mkfile(TEST_FILE, "[section]\n\tvalue = 1\n\n");

	/* By freeing the config, we make sure we flush the values  */
	cl_git_pass(git_config_open_ondisk(&cfg, TEST_FILE));

	cl_git_pass(git_config_get_int32(&v, cfg, "section.value"));
	cl_assert_equal_i(1, v);
	cl_git_fail(git_config_get_int32(&v, cfg, "section.newval"));

	cl_git_rewritefile(TEST_FILE, "[section]\n\tnewval = 10\n\n");

	cl_git_pass(git_config_get_int32(&v, cfg, "section.value"));
	cl_assert_equal_i(1, v);
	cl_git_fail(git_config_get_int32(&v, cfg, "section.newval"));

	cl_git_pass(git_config_refresh(cfg));

	cl_git_fail(git_config_get_int32(&v, cfg, "section.value"));
	cl_git_pass(git_config_get_int32(&v, cfg, "section.newval"));
	cl_assert_equal_i(10, v);

	git_config_free(cfg);
}
/**
 * ggit_config_refresh:
 * @config: a #GgitConfig.
 * @error: a #GError for error reporting, or %NULL.
 *
 * Reloads changed config files.
 *
 * A config file may be changed on disk out from under the in-memory
 * config object. This function causes us to look for files that have
 * been modified since we last loaded them and refresh the config with
 * the latest information.
 */
void
ggit_config_refresh (GgitConfig  *config,
                     GError     **error)
{
	gint ret;

	g_return_if_fail (GGIT_IS_CONFIG (config));
	g_return_if_fail (error == NULL || *error == NULL);

	ret = git_config_refresh (_ggit_native_get (config));

	if (ret != GIT_OK)
	{
		_ggit_error_set (error, ret);
	}
}