]> git.proxmox.com Git - libgit2.git/blame - tests/libgit2/config/rename.c
Merge https://salsa.debian.org/debian/libgit2 into proxmox/bullseye
[libgit2.git] / tests / libgit2 / 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{
9a97f49e 24 git_config_entry *ce;
96869a4e
RB
25
26 cl_git_pass(git_config_get_entry(
27 &ce, g_config, "branch.track-local.remote"));
28 cl_assert_equal_s(".", ce->value);
9a97f49e 29 git_config_entry_free(ce);
96869a4e
RB
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);
9a97f49e 40 git_config_entry_free(ce);
96869a4e
RB
41
42 cl_git_fail(git_config_get_entry(
43 &ce, g_config, "branch.track-local.remote"));
44}
45
46void test_config_rename__prevent_overwrite(void)
47{
9a97f49e 48 git_config_entry *ce;
96869a4e
RB
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);
9a97f49e 56 git_config_entry_free(ce);
96869a4e
RB
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);
9a97f49e 64 git_config_entry_free(ce);
96869a4e 65
25e0b157
RB
66 /* so, we don't currently prevent overwrite... */
67 /* {
68 const git_error *err;
ac3d33df 69 cl_assert((err = git_error_last()) != NULL);
25e0b157
RB
70 cl_assert(err->message != NULL);
71 } */
96869a4e
RB
72}
73
74static 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
82void 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}