]>
git.proxmox.com Git - libgit2.git/blob - tests/config/rename.c
be620c3078eb50da55aad5a67614250fb708ca81
1 #include "clar_libgit2.h"
4 static git_repository
*g_repo
= NULL
;
5 static git_config
*g_config
= NULL
;
7 void test_config_rename__initialize(void)
9 g_repo
= cl_git_sandbox_init("testrepo.git");
10 cl_git_pass(git_repository_config(&g_config
, g_repo
));
13 void test_config_rename__cleanup(void)
15 git_config_free(g_config
);
18 cl_git_sandbox_cleanup();
22 void test_config_rename__can_rename(void)
26 cl_git_pass(git_config_get_entry(
27 &ce
, g_config
, "branch.track-local.remote"));
28 cl_assert_equal_s(".", ce
->value
);
29 git_config_entry_free(ce
);
31 cl_git_fail(git_config_get_entry(
32 &ce
, g_config
, "branch.local-track.remote"));
34 cl_git_pass(git_config_rename_section(
35 g_repo
, "branch.track-local", "branch.local-track"));
37 cl_git_pass(git_config_get_entry(
38 &ce
, g_config
, "branch.local-track.remote"));
39 cl_assert_equal_s(".", ce
->value
);
40 git_config_entry_free(ce
);
42 cl_git_fail(git_config_get_entry(
43 &ce
, g_config
, "branch.track-local.remote"));
46 void test_config_rename__prevent_overwrite(void)
50 cl_git_pass(git_config_set_string(
51 g_config
, "branch.local-track.remote", "yellow"));
53 cl_git_pass(git_config_get_entry(
54 &ce
, g_config
, "branch.local-track.remote"));
55 cl_assert_equal_s("yellow", ce
->value
);
56 git_config_entry_free(ce
);
58 cl_git_pass(git_config_rename_section(
59 g_repo
, "branch.track-local", "branch.local-track"));
61 cl_git_pass(git_config_get_entry(
62 &ce
, g_config
, "branch.local-track.remote"));
63 cl_assert_equal_s(".", ce
->value
);
64 git_config_entry_free(ce
);
66 /* so, we don't currently prevent overwrite... */
69 cl_assert((err = git_error_last()) != NULL);
70 cl_assert(err->message != NULL);
74 static void assert_invalid_config_section_name(
75 git_repository
*repo
, const char *name
)
78 git_config_rename_section(repo
, "branch.remoteless", name
),
82 void test_config_rename__require_a_valid_new_name(void)
84 assert_invalid_config_section_name(g_repo
, "");
85 assert_invalid_config_section_name(g_repo
, "bra\nch");
86 assert_invalid_config_section_name(g_repo
, "branc#");
87 assert_invalid_config_section_name(g_repo
, "bra\nch.duh");
88 assert_invalid_config_section_name(g_repo
, "branc#.duh");