]> git.proxmox.com Git - libgit2.git/blob - tests/config/rename.c
be620c3078eb50da55aad5a67614250fb708ca81
[libgit2.git] / tests / config / rename.c
1 #include "clar_libgit2.h"
2 #include "config.h"
3
4 static git_repository *g_repo = NULL;
5 static git_config *g_config = NULL;
6
7 void test_config_rename__initialize(void)
8 {
9 g_repo = cl_git_sandbox_init("testrepo.git");
10 cl_git_pass(git_repository_config(&g_config, g_repo));
11 }
12
13 void test_config_rename__cleanup(void)
14 {
15 git_config_free(g_config);
16 g_config = NULL;
17
18 cl_git_sandbox_cleanup();
19 g_repo = NULL;
20 }
21
22 void test_config_rename__can_rename(void)
23 {
24 git_config_entry *ce;
25
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);
30
31 cl_git_fail(git_config_get_entry(
32 &ce, g_config, "branch.local-track.remote"));
33
34 cl_git_pass(git_config_rename_section(
35 g_repo, "branch.track-local", "branch.local-track"));
36
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);
41
42 cl_git_fail(git_config_get_entry(
43 &ce, g_config, "branch.track-local.remote"));
44 }
45
46 void test_config_rename__prevent_overwrite(void)
47 {
48 git_config_entry *ce;
49
50 cl_git_pass(git_config_set_string(
51 g_config, "branch.local-track.remote", "yellow"));
52
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);
57
58 cl_git_pass(git_config_rename_section(
59 g_repo, "branch.track-local", "branch.local-track"));
60
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);
65
66 /* so, we don't currently prevent overwrite... */
67 /* {
68 const git_error *err;
69 cl_assert((err = git_error_last()) != NULL);
70 cl_assert(err->message != NULL);
71 } */
72 }
73
74 static void assert_invalid_config_section_name(
75 git_repository *repo, const char *name)
76 {
77 cl_git_fail_with(
78 git_config_rename_section(repo, "branch.remoteless", name),
79 GIT_EINVALIDSPEC);
80 }
81
82 void test_config_rename__require_a_valid_new_name(void)
83 {
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");
89 }