diff options
author | Jameson Miller <jamill@microsoft.com> | 2013-03-01 20:07:53 +0400 |
---|---|---|
committer | Jameson Miller <jamill@microsoft.com> | 2013-03-01 23:56:09 +0400 |
commit | 926acbcf8ed80a69ab82f3d14e90dabeca9af07d (patch) | |
tree | 550f4e6314038033bbbced49b5934e1706405278 /tests-clar/clone | |
parent | cc427158d4fafa26e3d2d9f69da51a1a8d8a92d4 (diff) |
Clone should not delete directories it did not create
Diffstat (limited to 'tests-clar/clone')
-rw-r--r-- | tests-clar/clone/nonetwork.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c index 3d327cb1e..2c4cba4eb 100644 --- a/tests-clar/clone/nonetwork.c +++ b/tests-clar/clone/nonetwork.c @@ -52,6 +52,43 @@ void test_clone_nonetwork__bad_url(void) cl_assert(!git_path_exists("./foo")); } +static int dont_call_me(void *state, git_buf *path) +{ + GIT_UNUSED(state); + GIT_UNUSED(path); + return GIT_ERROR; +} + +void test_clone_nonetwork__do_not_clean_existing_directory(void) +{ + git_buf path_buf = GIT_BUF_INIT; + + git_buf_put(&path_buf, "./foo", 5); + + /* Clone should not remove the directory if it already exists, but + * Should clean up entries it creates. */ + p_mkdir("./foo", GIT_DIR_MODE); + cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options)); + cl_assert(git_path_exists("./foo")); + + /* Make sure the directory is empty. */ + cl_git_pass(git_path_direach(&path_buf, + dont_call_me, + NULL)); + + /* Try again with a bare repository. */ + g_options.bare = true; + cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options)); + cl_assert(git_path_exists("./foo")); + + /* Make sure the directory is empty. */ + cl_git_pass(git_path_direach(&path_buf, + dont_call_me, + NULL)); + + git_buf_free(&path_buf); +} + void test_clone_nonetwork__local(void) { cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options)); |