summaryrefslogtreecommitdiff
path: root/src/clone.c
diff options
context:
space:
mode:
authorJameson Miller <jamill@microsoft.com>2013-03-01 11:07:53 -0500
committerJameson Miller <jamill@microsoft.com>2013-03-01 14:56:09 -0500
commit926acbcf8ed80a69ab82f3d14e90dabeca9af07d (patch)
tree550f4e6314038033bbbced49b5934e1706405278 /src/clone.c
parentcc427158d4fafa26e3d2d9f69da51a1a8d8a92d4 (diff)
downloadlibgit2-926acbcf8ed80a69ab82f3d14e90dabeca9af07d.tar.gz
Clone should not delete directories it did not create
Diffstat (limited to 'src/clone.c')
-rw-r--r--src/clone.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/clone.c b/src/clone.c
index 409a77f92..0bbccd44b 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -429,6 +429,7 @@ int git_clone(
int retcode = GIT_ERROR;
git_repository *repo = NULL;
git_clone_options normOptions;
+ int remove_directory_on_failure = 0;
assert(out && url && local_path);
@@ -439,11 +440,19 @@ int git_clone(
return GIT_ERROR;
}
+ /* Only remove the directory on failure if we create it */
+ remove_directory_on_failure = !git_path_exists(local_path);
+
if (!(retcode = git_repository_init(&repo, local_path, normOptions.bare))) {
if ((retcode = setup_remotes_and_fetch(repo, url, &normOptions)) < 0) {
/* Failed to fetch; clean up */
git_repository_free(repo);
- git_futils_rmdir_r(local_path, NULL, GIT_RMDIR_REMOVE_FILES);
+
+ if (remove_directory_on_failure)
+ git_futils_rmdir_r(local_path, NULL, GIT_RMDIR_REMOVE_FILES);
+ else
+ git_futils_cleanupdir_r(local_path);
+
} else {
*out = repo;
retcode = 0;