summaryrefslogtreecommitdiff
path: root/src/clone.c
diff options
context:
space:
mode:
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;