tests: submodule: test cloning edge cases Add two more tests that verify our behaviour in some edge cases, notably when cloning into a non-empty directory and when cloning the same submodule twice.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
diff --git a/tests/submodule/add.c b/tests/submodule/add.c
index 76c3fff..f4d1e3b 100644
--- a/tests/submodule/add.c
+++ b/tests/submodule/add.c
@@ -212,3 +212,40 @@ void test_submodule_add__submodule_clone(void)
git_submodule_free(sm);
git_index_free(index);
}
+
+void test_submodule_add__submodule_clone_into_nonempty_dir_succeeds(void)
+{
+ git_submodule *sm;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ cl_git_pass(p_mkdir("empty_standard_repo/sm", 0777));
+ cl_git_mkfile("empty_standard_repo/sm/foobar", "");
+
+ /* Create the submodule structure, clone into it and finalize */
+ cl_git_pass(git_submodule_add_setup(&sm, g_repo, cl_fixture("testrepo.git"), "sm", true));
+ cl_git_pass(git_submodule_clone(NULL, sm, NULL));
+ cl_git_pass(git_submodule_add_finalize(sm));
+
+ cl_assert(git_path_exists("empty_standard_repo/sm/foobar"));
+
+ assert_submodule_exists(g_repo, "sm");
+
+ git_submodule_free(sm);
+}
+
+void test_submodule_add__submodule_clone_twice_fails(void)
+{
+ git_submodule *sm;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ /* Create the submodule structure, clone into it and finalize */
+ cl_git_pass(git_submodule_add_setup(&sm, g_repo, cl_fixture("testrepo.git"), "sm", true));
+ cl_git_pass(git_submodule_clone(NULL, sm, NULL));
+ cl_git_pass(git_submodule_add_finalize(sm));
+
+ cl_git_fail(git_submodule_clone(NULL, sm, NULL));
+
+ git_submodule_free(sm);
+}