]> git.proxmox.com Git - libgit2.git/commitdiff
clone: re-allow using a custom remote name
authorCarlos Martín Nieto <cmn@dwim.me>
Fri, 20 Sep 2013 20:57:01 +0000 (22:57 +0200)
committerCarlos Martín Nieto <cmn@dwim.me>
Wed, 2 Oct 2013 04:42:26 +0000 (06:42 +0200)
This is a small thing that by itself doesn't quite justify making the
user use clone_into.

include/git2/clone.h
src/clone.c
tests-clar/clone/nonetwork.c

index a59de1bc7039de1329c51cef25e67e72e74b8906..bd602fb7a59961e2d32d010302219f0a0cb30055 100644 (file)
@@ -35,25 +35,12 @@ GIT_BEGIN_DECL
  *   set the `checkout_strategy` to GIT_CHECKOUT_DEFAULT.
  * - `bare` should be set to zero to create a standard repo, non-zero for
  *   a bare repo
- * - `fetch_progress_cb` is optional callback for fetch progress. Be aware that
- *   this is called inline with network and indexing operations, so performance
- *   may be affected.
- * - `fetch_progress_payload` is payload for fetch_progress_cb
+ * - `ignore_cert_errors` should be set to 1 if errors validating the remote host's
+ *   certificate should be ignored.
  *
  *   ** "origin" remote options: **
  * - `remote_name` is the name given to the "origin" remote.  The default is
  *   "origin".
- * - `pushurl` is a URL to be used for pushing.  NULL means use the fetch url.
- * - `fetch_spec` is the fetch specification to be used for fetching.  NULL
- *   results in the same behavior as GIT_REMOTE_DEFAULT_FETCH.
- * - `push_spec` is the fetch specification to be used for pushing.  NULL means
- *   use the same spec as for fetching.
- * - `transport_flags` is flags used to create transport if no transport is
- *   provided.
- * - `transport` is a custom transport to be used for the initial fetch.  NULL
- *   means use the transport autodetected from the URL.
- * - `remote_callbacks` may be used to specify custom progress callbacks for
- *   the origin remote before the fetch is initiated.
  * - `checkout_branch` gives the name of the branch to checkout. NULL means
  *   use the remote's HEAD.
  */
@@ -62,10 +49,11 @@ typedef struct git_clone_options {
        unsigned int version;
 
        git_checkout_opts checkout_opts;
+       git_remote_callbacks *remote_callbacks;
+
        int bare;
        int ignore_cert_errors;
-
-       git_remote_callbacks *remote_callbacks;
+       const char *remote_name;
        const char* checkout_branch;
 } git_clone_options;
 
index 60525939f0972eb14aeff254293f93db9209d7aa..cad9ea1dc591d4f53a24b06dfed848065b39a8c2 100644 (file)
@@ -306,8 +306,10 @@ static int create_and_configure_origin(
 {
        int error;
        git_remote *origin = NULL;
+       const char *name;
 
-       if ((error = git_remote_create(&origin, repo, "origin", url)) < 0)
+       name = options->remote_name ? options->remote_name : "origin";
+       if ((error = git_remote_create(&origin, repo, name, url)) < 0)
                goto on_error;
 
        if (options->ignore_cert_errors)
index 84654fa5a42a223e3e24d8c0014b5fbacb8ecc72..c7a2192594448cc320689e66a5fc2522fd2554ec 100644 (file)
@@ -122,6 +122,15 @@ 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__cope_with_already_existing_directory(void)
 {
        p_mkdir("./foo", GIT_DIR_MODE);