]> git.proxmox.com Git - libgit2.git/blame - tests/config/rename.c
Improve GIT_EUSER handling
[libgit2.git] / tests / config / rename.c
CommitLineData
96869a4e
RB
1#include "clar_libgit2.h"
2#include "config.h"
3
4static git_repository *g_repo = NULL;
5static git_config *g_config = NULL;
6
7void 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
13void 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
22void test_config_rename__can_rename(void)
23{
24 const 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
30 cl_git_fail(git_config_get_entry(
31 &ce, g_config, "branch.local-track.remote"));
32
33 cl_git_pass(git_config_rename_section(
34 g_repo, "branch.track-local", "branch.local-track"));
35
36 cl_git_pass(git_config_get_entry(
37 &ce, g_config, "branch.local-track.remote"));
38 cl_assert_equal_s(".", ce->value);
39
40 cl_git_fail(git_config_get_entry(
41 &ce, g_config, "branch.track-local.remote"));
42}
43
44void test_config_rename__prevent_overwrite(void)
45{
46 const git_config_entry *ce;
47 const git_error *err;
48
49 cl_git_pass(git_config_set_string(
50 g_config, "branch.local-track.remote", "yellow"));
51
52 cl_git_pass(git_config_get_entry(
53 &ce, g_config, "branch.local-track.remote"));
54 cl_assert_equal_s("yellow", ce->value);
55
56 cl_git_pass(git_config_rename_section(
57 g_repo, "branch.track-local", "branch.local-track"));
58
59 cl_git_pass(git_config_get_entry(
60 &ce, g_config, "branch.local-track.remote"));
61 cl_assert_equal_s(".", ce->value);
62
63// cl_assert((err = giterr_last()) != NULL);
64// cl_assert(err->message != NULL);
65}
66
67static void assert_invalid_config_section_name(
68 git_repository *repo, const char *name)
69{
70 cl_git_fail_with(
71 git_config_rename_section(repo, "branch.remoteless", name),
72 GIT_EINVALIDSPEC);
73}
74
75void test_config_rename__require_a_valid_new_name(void)
76{
77 assert_invalid_config_section_name(g_repo, "");
78 assert_invalid_config_section_name(g_repo, "bra\nch");
79 assert_invalid_config_section_name(g_repo, "branc#");
80 assert_invalid_config_section_name(g_repo, "bra\nch.duh");
81 assert_invalid_config_section_name(g_repo, "branc#.duh");
82}