Hash :
2a7086fa
Author :
Date :
2017-04-25T13:23:04
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#include "clar_libgit2.h"
#include "config_file.h"
#include "config.h"
static git_config *cfg;
void test_config_readonly__initialize(void)
{
cl_git_pass(git_config_new(&cfg));
}
void test_config_readonly__cleanup(void)
{
git_config_free(cfg);
cfg = NULL;
}
void test_config_readonly__writing_to_readonly_fails(void)
{
git_config_backend *backend;
cl_git_pass(git_config_file__ondisk(&backend, "global"));
backend->readonly = 1;
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, 0));
cl_git_fail_with(GIT_ENOTFOUND, git_config_set_string(cfg, "foo.bar", "baz"));
cl_assert(!git_path_exists("global"));
}
void test_config_readonly__writing_to_cfg_with_rw_precedence_succeeds(void)
{
git_config_backend *backend;
cl_git_pass(git_config_file__ondisk(&backend, "global"));
backend->readonly = 1;
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, 0));
cl_git_pass(git_config_file__ondisk(&backend, "local"));
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_LOCAL, 0));
cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz"));
cl_assert(git_path_exists("local"));
cl_assert(!git_path_exists("global"));
cl_git_pass(p_unlink("local"));
}
void test_config_readonly__writing_to_cfg_with_ro_precedence_succeeds(void)
{
git_config_backend *backend;
cl_git_pass(git_config_file__ondisk(&backend, "local"));
backend->readonly = 1;
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_LOCAL, 0));
cl_git_pass(git_config_file__ondisk(&backend, "global"));
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, 0));
cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz"));
cl_assert(!git_path_exists("local"));
cl_assert(git_path_exists("global"));
cl_git_pass(p_unlink("global"));
}