]>
git.proxmox.com Git - libgit2.git/blob - tests/network/remote/rename.c
1 #include "clar_libgit2.h"
2 #include "config/config_helpers.h"
4 #include "repository.h"
6 static git_remote
*_remote
;
7 static git_repository
*_repo
;
9 void test_network_remote_rename__initialize(void)
11 _repo
= cl_git_sandbox_init("testrepo.git");
13 cl_git_pass(git_remote_load(&_remote
, _repo
, "test"));
16 void test_network_remote_rename__cleanup(void)
18 git_remote_free(_remote
);
21 cl_git_sandbox_cleanup();
24 static int dont_call_me_cb(const char *fetch_refspec
, void *payload
)
26 GIT_UNUSED(fetch_refspec
);
34 void test_network_remote_rename__renaming_a_remote_moves_related_configuration_section(void)
36 assert_config_entry_existence(_repo
, "remote.test.fetch", true);
37 assert_config_entry_existence(_repo
, "remote.just/renamed.fetch", false);
39 cl_git_pass(git_remote_rename(_remote
, "just/renamed", dont_call_me_cb
, NULL
));
41 assert_config_entry_existence(_repo
, "remote.test.fetch", false);
42 assert_config_entry_existence(_repo
, "remote.just/renamed.fetch", true);
45 void test_network_remote_rename__renaming_a_remote_updates_branch_related_configuration_entries(void)
47 assert_config_entry_value(_repo
, "branch.master.remote", "test");
49 cl_git_pass(git_remote_rename(_remote
, "just/renamed", dont_call_me_cb
, NULL
));
51 assert_config_entry_value(_repo
, "branch.master.remote", "just/renamed");
54 void test_network_remote_rename__renaming_a_remote_updates_default_fetchrefspec(void)
56 cl_git_pass(git_remote_rename(_remote
, "just/renamed", dont_call_me_cb
, NULL
));
58 assert_config_entry_value(_repo
, "remote.just/renamed.fetch", "+refs/heads/*:refs/remotes/just/renamed/*");
61 void test_network_remote_rename__renaming_a_remote_without_a_fetchrefspec_doesnt_create_one(void)
65 git_remote_free(_remote
);
66 cl_git_pass(git_repository_config__weakptr(&config
, _repo
));
67 cl_git_pass(git_config_delete_entry(config
, "remote.test.fetch"));
69 cl_git_pass(git_remote_load(&_remote
, _repo
, "test"));
71 assert_config_entry_existence(_repo
, "remote.test.fetch", false);
73 cl_git_pass(git_remote_rename(_remote
, "just/renamed", dont_call_me_cb
, NULL
));
75 assert_config_entry_existence(_repo
, "remote.just/renamed.fetch", false);
78 static int ensure_refspecs(const char* refspec_name
, void *payload
)
82 const char ** exp
= (const char **)payload
;
85 if (strcmp(exp
[i
++], refspec_name
))
97 void test_network_remote_rename__renaming_a_remote_notifies_of_non_default_fetchrefspec(void)
101 char *expected_refspecs
[] = {
106 git_remote_free(_remote
);
107 cl_git_pass(git_repository_config__weakptr(&config
, _repo
));
108 cl_git_pass(git_config_set_string(config
, "remote.test.fetch", "+refs/*:refs/*"));
109 cl_git_pass(git_remote_load(&_remote
, _repo
, "test"));
111 cl_git_pass(git_remote_rename(_remote
, "just/renamed", ensure_refspecs
, &expected_refspecs
));
113 assert_config_entry_value(_repo
, "remote.just/renamed.fetch", "+refs/*:refs/*");
116 void test_network_remote_rename__new_name_can_contain_dots(void)
118 cl_git_pass(git_remote_rename(_remote
, "just.renamed", dont_call_me_cb
, NULL
));
119 cl_assert_equal_s("just.renamed", git_remote_name(_remote
));
122 void test_network_remote_rename__new_name_must_conform_to_reference_naming_conventions(void)
126 git_remote_rename(_remote
, "new@{name", dont_call_me_cb
, NULL
));
129 void test_network_remote_rename__renamed_name_is_persisted(void)
132 git_repository
*another_repo
;
134 cl_git_fail(git_remote_load(&renamed
, _repo
, "just/renamed"));
136 cl_git_pass(git_remote_rename(_remote
, "just/renamed", dont_call_me_cb
, NULL
));
138 cl_git_pass(git_repository_open(&another_repo
, "testrepo.git"));
139 cl_git_pass(git_remote_load(&renamed
, _repo
, "just/renamed"));
141 git_remote_free(renamed
);
142 git_repository_free(another_repo
);
145 void test_network_remote_rename__cannot_overwrite_an_existing_remote(void)
147 cl_assert_equal_i(GIT_EEXISTS
, git_remote_rename(_remote
, "test", dont_call_me_cb
, NULL
));
148 cl_assert_equal_i(GIT_EEXISTS
, git_remote_rename(_remote
, "test_with_pushurl", dont_call_me_cb
, NULL
));
151 void test_network_remote_rename__renaming_a_remote_moves_the_underlying_reference(void)
153 git_reference
*underlying
;
155 cl_assert_equal_i(GIT_ENOTFOUND
, git_reference_lookup(&underlying
, _repo
, "refs/remotes/just/renamed"));
156 cl_git_pass(git_reference_lookup(&underlying
, _repo
, "refs/remotes/test/master"));
157 git_reference_free(underlying
);
159 cl_git_pass(git_remote_rename(_remote
, "just/renamed", dont_call_me_cb
, NULL
));
161 cl_assert_equal_i(GIT_ENOTFOUND
, git_reference_lookup(&underlying
, _repo
, "refs/remotes/test/master"));
162 cl_git_pass(git_reference_lookup(&underlying
, _repo
, "refs/remotes/just/renamed/master"));
163 git_reference_free(underlying
);
166 void test_network_remote_rename__cannot_rename_an_inmemory_remote(void)
170 cl_git_pass(git_remote_create_anonymous(&remote
, _repo
, "file:///blah", NULL
));
171 cl_git_fail(git_remote_rename(remote
, "newname", NULL
, NULL
));
173 git_remote_free(remote
);