Skip to content

Commit 73e9535

Browse files
committed
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 parent de412fc commit 73e9535

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/submodule/add.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,40 @@ void test_submodule_add__submodule_clone(void)
212212
git_submodule_free(sm);
213213
git_index_free(index);
214214
}
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

Comments
 (0)