Hash :
96869a4e
Author :
Date :
2013-12-03T16:45:39
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#include "clar_libgit2.h"
#include "config.h"
static git_repository *g_repo = NULL;
static git_config *g_config = NULL;
void test_config_rename__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_repository_config(&g_config, g_repo));
}
void test_config_rename__cleanup(void)
{
git_config_free(g_config);
g_config = NULL;
cl_git_sandbox_cleanup();
g_repo = NULL;
}
void test_config_rename__can_rename(void)
{
const git_config_entry *ce;
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.track-local.remote"));
cl_assert_equal_s(".", ce->value);
cl_git_fail(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
cl_git_pass(git_config_rename_section(
g_repo, "branch.track-local", "branch.local-track"));
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
cl_assert_equal_s(".", ce->value);
cl_git_fail(git_config_get_entry(
&ce, g_config, "branch.track-local.remote"));
}
void test_config_rename__prevent_overwrite(void)
{
const git_config_entry *ce;
cl_git_pass(git_config_set_string(
g_config, "branch.local-track.remote", "yellow"));
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
cl_assert_equal_s("yellow", ce->value);
cl_git_pass(git_config_rename_section(
g_repo, "branch.track-local", "branch.local-track"));
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
cl_assert_equal_s(".", ce->value);
/* so, we don't currently prevent overwrite... */
/* {
const git_error *err;
cl_assert((err = giterr_last()) != NULL);
cl_assert(err->message != NULL);
} */
}
static void assert_invalid_config_section_name(
git_repository *repo, const char *name)
{
cl_git_fail_with(
git_config_rename_section(repo, "branch.remoteless", name),
GIT_EINVALIDSPEC);
}
void test_config_rename__require_a_valid_new_name(void)
{
assert_invalid_config_section_name(g_repo, "");
assert_invalid_config_section_name(g_repo, "bra\nch");
assert_invalid_config_section_name(g_repo, "branc#");
assert_invalid_config_section_name(g_repo, "bra\nch.duh");
assert_invalid_config_section_name(g_repo, "branc#.duh");
}