clone: remove more options from basic clone The basic clone function is there to make it easy to create a "normal" clone. Remove a bunch of options that are about changing the remote's configuration.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
diff --git a/include/git2/clone.h b/include/git2/clone.h
index c80bf9b..0a89b57 100644
--- a/include/git2/clone.h
+++ b/include/git2/clone.h
@@ -62,15 +62,8 @@ typedef struct git_clone_options {
unsigned int version;
git_checkout_opts checkout_opts;
- git_repository_init_options *init_options;
int bare;
- const char *remote_name;
- const char *pushurl;
- const char *fetch_spec;
- const char *push_spec;
- git_transport_flags_t transport_flags;
- git_transport *transport;
git_remote_callbacks *remote_callbacks;
const char* checkout_branch;
} git_clone_options;
diff --git a/src/clone.c b/src/clone.c
index 3df3170..abea0bd 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -307,31 +307,13 @@ static int create_and_configure_origin(
int error;
git_remote *origin = NULL;
- if ((error = git_remote_create(&origin, repo, options->remote_name, url)) < 0)
+ if ((error = git_remote_create(&origin, repo, "origin", url)) < 0)
goto on_error;
if (options->remote_callbacks &&
(error = git_remote_set_callbacks(origin, options->remote_callbacks)) < 0)
goto on_error;
- if (options->fetch_spec) {
- git_remote_clear_refspecs(origin);
- if ((error = git_remote_add_fetch(origin, options->fetch_spec)) < 0)
- goto on_error;
- }
-
- if (options->push_spec &&
- (error = git_remote_add_push(origin, options->push_spec)) < 0)
- goto on_error;
-
- if (options->pushurl &&
- (error = git_remote_set_pushurl(origin, options->pushurl)) < 0)
- goto on_error;
-
- if (options->transport_flags == GIT_TRANSPORTFLAGS_NO_CHECK_CERT) {
- git_remote_check_cert(origin, 0);
- }
-
if ((error = git_remote_save(origin)) < 0)
goto on_error;
@@ -360,23 +342,6 @@ static bool should_checkout(
return !git_repository_head_unborn(repo);
}
-static void normalize_options(git_clone_options *dst, const git_clone_options *src, git_repository_init_options *initOptions)
-{
- git_clone_options default_options = GIT_CLONE_OPTIONS_INIT;
- if (!src) src = &default_options;
-
- *dst = *src;
-
- /* Provide defaults for null pointers */
- if (!dst->remote_name) dst->remote_name = "origin";
- if (!dst->init_options) {
- dst->init_options = initOptions;
- initOptions->flags = GIT_REPOSITORY_INIT_MKPATH;
- if (dst->bare)
- initOptions->flags |= GIT_REPOSITORY_INIT_BARE;
- }
-}
-
int git_clone_into(git_repository *repo, git_remote *remote, git_checkout_opts *co_opts, const char *branch)
{
int error = 0, old_fetchhead;
@@ -425,14 +390,11 @@ int git_clone(
int retcode = GIT_ERROR;
git_repository *repo = NULL;
git_remote *origin;
- git_clone_options normOptions;
int remove_directory_on_failure = 0;
- git_repository_init_options initOptions = GIT_REPOSITORY_INIT_OPTIONS_INIT;
assert(out && url && local_path);
- normalize_options(&normOptions, options, &initOptions);
- GITERR_CHECK_VERSION(&normOptions, GIT_CLONE_OPTIONS_VERSION, "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)) {
@@ -444,13 +406,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_ext(&repo, local_path, normOptions.init_options)) < 0)
+ if ((retcode = git_repository_init(&repo, local_path, options->bare)) < 0)
return retcode;
- if ((retcode = create_and_configure_origin(&origin, repo, url, &normOptions)) < 0)
+ if ((retcode = create_and_configure_origin(&origin, repo, url, options)) < 0)
goto cleanup;
- retcode = git_clone_into(repo, origin, &normOptions.checkout_opts, normOptions.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 3824916..84654fa 100644
--- a/tests-clar/clone/nonetwork.c
+++ b/tests-clar/clone/nonetwork.c
@@ -122,55 +122,6 @@ void test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory(vo
cl_git_fail(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
}
-void test_clone_nonetwork__custom_origin_name(void)
-{
- g_options.remote_name = "my_origin";
- cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
-
- cl_git_pass(git_remote_load(&g_remote, g_repo, "my_origin"));
-}
-
-void test_clone_nonetwork__custom_push_url(void)
-{
- const char *url = "http://example.com";
-
- g_options.pushurl = url;
- cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
-
- cl_git_pass(git_remote_load(&g_remote, g_repo, "origin"));
- cl_assert_equal_s(url, git_remote_pushurl(g_remote));
-}
-
-void test_clone_nonetwork__custom_fetch_spec(void)
-{
- const git_refspec *actual_fs;
- const char *spec = "+refs/heads/master:refs/heads/foo";
-
- g_options.fetch_spec = spec;
- cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
-
- cl_git_pass(git_remote_load(&g_remote, g_repo, "origin"));
- actual_fs = git_remote_get_refspec(g_remote, 0);
- cl_assert_equal_s("refs/heads/master", git_refspec_src(actual_fs));
- cl_assert_equal_s("refs/heads/foo", git_refspec_dst(actual_fs));
-
- cl_git_pass(git_reference_lookup(&g_ref, g_repo, "refs/heads/foo"));
-}
-
-void test_clone_nonetwork__custom_push_spec(void)
-{
- const git_refspec *actual_fs;
- const char *spec = "+refs/heads/master:refs/heads/foo";
-
- g_options.push_spec = spec;
- cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
-
- cl_git_pass(git_remote_load(&g_remote, g_repo, "origin"));
- actual_fs = git_remote_get_refspec(g_remote, git_remote_refspec_count(g_remote) - 1);
- cl_assert_equal_s("refs/heads/master", git_refspec_src(actual_fs));
- cl_assert_equal_s("refs/heads/foo", git_refspec_dst(actual_fs));
-}
-
void test_clone_nonetwork__cope_with_already_existing_directory(void)
{
p_mkdir("./foo", GIT_DIR_MODE);