diff --git a/src/clone.c b/src/clone.c index cad9ea1dc..1af6e393f 100644 --- a/src/clone.c +++ b/src/clone.c @@ -390,16 +390,20 @@ int git_clone( git_repository **out, const char *url, const char *local_path, - const git_clone_options *options) + const git_clone_options *_options) { int retcode = GIT_ERROR; git_repository *repo = NULL; git_remote *origin; + git_clone_options options = GIT_CLONE_OPTIONS_INIT; int remove_directory_on_failure = 0; assert(out && url && local_path); - GITERR_CHECK_VERSION(options, GIT_CLONE_OPTIONS_VERSION, "git_clone_options"); + if (_options) + memcpy(&options, _options, sizeof(git_clone_options)); + + GITERR_CHECK_VERSION(&options, GIT_CLONE_OPTIONS_VERSION, "git_clone_options"); /* Only clone to a new directory or an empty directory */ if (git_path_exists(local_path) && !git_path_is_empty_dir(local_path)) { @@ -411,13 +415,13 @@ int git_clone( /* 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, options->bare)) < 0) + if ((retcode = git_repository_init(&repo, local_path, options.bare)) < 0) return retcode; - if ((retcode = create_and_configure_origin(&origin, repo, url, options)) < 0) + if ((retcode = create_and_configure_origin(&origin, repo, url, &options)) < 0) goto cleanup; - retcode = git_clone_into(repo, origin, &options->checkout_opts, options->checkout_branch); + retcode = git_clone_into(repo, origin, &options.checkout_opts, options.checkout_branch); git_remote_free(origin); if (retcode < 0) diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c index c7a219259..9b666b3f7 100644 --- a/tests-clar/clone/nonetwork.c +++ b/tests-clar/clone/nonetwork.c @@ -130,6 +130,12 @@ void test_clone_nonetwork__custom_origin_name(void) cl_git_pass(git_remote_load(&g_remote, g_repo, "my_origin")); } +void test_clone_nonetwork__defaults(void) +{ + cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", NULL)); + cl_assert(g_repo); + cl_git_pass(git_remote_load(&g_remote, g_repo, "origin")); +} void test_clone_nonetwork__cope_with_already_existing_directory(void) {