|
5 | 5 | #include "config/config_helpers.h" |
6 | 6 | #include "futils.h" |
7 | 7 | #include "repository.h" |
| 8 | +#include "git2/sys/commit.h" |
8 | 9 |
|
9 | 10 | static git_repository *g_repo = NULL; |
10 | 11 | static const char *valid_blob_id = "fa49b077972391ad58037050f2a75f74e3671e92"; |
@@ -183,3 +184,68 @@ void test_submodule_add__file_exists_in_index(void) |
183 | 184 | git_submodule_free(sm); |
184 | 185 | git_buf_dispose(&name); |
185 | 186 | } |
| 187 | + |
| 188 | +void test_submodule_add__submodule_clone(void) |
| 189 | +{ |
| 190 | + git_oid tree_id, commit_id; |
| 191 | + git_signature *sig; |
| 192 | + git_submodule *sm; |
| 193 | + git_index *index; |
| 194 | + |
| 195 | + g_repo = cl_git_sandbox_init("empty_standard_repo"); |
| 196 | + |
| 197 | + /* Create the submodule structure, clone into it and finalize */ |
| 198 | + cl_git_pass(git_submodule_add_setup(&sm, g_repo, cl_fixture("testrepo.git"), "testrepo-add", true)); |
| 199 | + cl_git_pass(git_submodule_clone(NULL, sm, NULL)); |
| 200 | + cl_git_pass(git_submodule_add_finalize(sm)); |
| 201 | + |
| 202 | + /* Create the submodule commit */ |
| 203 | + cl_git_pass(git_repository_index(&index, g_repo)); |
| 204 | + cl_git_pass(git_index_write_tree(&tree_id, index)); |
| 205 | + cl_git_pass(git_signature_now(&sig, "Submoduler", "submoduler@local")); |
| 206 | + cl_git_pass(git_commit_create_from_ids(&commit_id, g_repo, "HEAD", sig, sig, NULL, "A submodule\n", |
| 207 | + &tree_id, 0, NULL)); |
| 208 | + |
| 209 | + assert_submodule_exists(g_repo, "testrepo-add"); |
| 210 | + |
| 211 | + git_signature_free(sig); |
| 212 | + git_submodule_free(sm); |
| 213 | + git_index_free(index); |
| 214 | +} |
| 215 | + |
| 216 | +void test_submodule_add__submodule_clone_into_nonempty_dir_succeeds(void) |
| 217 | +{ |
| 218 | + git_submodule *sm; |
| 219 | + |
| 220 | + g_repo = cl_git_sandbox_init("empty_standard_repo"); |
| 221 | + |
| 222 | + cl_git_pass(p_mkdir("empty_standard_repo/sm", 0777)); |
| 223 | + cl_git_mkfile("empty_standard_repo/sm/foobar", ""); |
| 224 | + |
| 225 | + /* Create the submodule structure, clone into it and finalize */ |
| 226 | + cl_git_pass(git_submodule_add_setup(&sm, g_repo, cl_fixture("testrepo.git"), "sm", true)); |
| 227 | + cl_git_pass(git_submodule_clone(NULL, sm, NULL)); |
| 228 | + cl_git_pass(git_submodule_add_finalize(sm)); |
| 229 | + |
| 230 | + cl_assert(git_path_exists("empty_standard_repo/sm/foobar")); |
| 231 | + |
| 232 | + assert_submodule_exists(g_repo, "sm"); |
| 233 | + |
| 234 | + git_submodule_free(sm); |
| 235 | +} |
| 236 | + |
| 237 | +void test_submodule_add__submodule_clone_twice_fails(void) |
| 238 | +{ |
| 239 | + git_submodule *sm; |
| 240 | + |
| 241 | + g_repo = cl_git_sandbox_init("empty_standard_repo"); |
| 242 | + |
| 243 | + /* Create the submodule structure, clone into it and finalize */ |
| 244 | + cl_git_pass(git_submodule_add_setup(&sm, g_repo, cl_fixture("testrepo.git"), "sm", true)); |
| 245 | + cl_git_pass(git_submodule_clone(NULL, sm, NULL)); |
| 246 | + cl_git_pass(git_submodule_add_finalize(sm)); |
| 247 | + |
| 248 | + cl_git_fail(git_submodule_clone(NULL, sm, NULL)); |
| 249 | + |
| 250 | + git_submodule_free(sm); |
| 251 | +} |
0 commit comments