Do not write tagopt configuration option on clone by default
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
diff --git a/src/clone.c b/src/clone.c
index aeb7bbf..9cde6f6 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -358,31 +358,41 @@ static int setup_remotes_and_fetch(
git_remote *origin;
/* Construct an origin remote */
- if (!create_and_configure_origin(&origin, repo, url, options)) {
- git_remote_set_update_fetchhead(origin, 0);
-
- /* Connect and download everything */
- if (!git_remote_connect(origin, GIT_DIRECTION_FETCH)) {
- if (!(retcode = git_remote_download(origin, options->fetch_progress_cb,
- options->fetch_progress_payload))) {
- /* Create "origin/foo" branches for all remote branches */
- if (!git_remote_update_tips(origin)) {
- /* Point HEAD to the requested branch */
- if (options->checkout_branch) {
- if (!update_head_to_branch(repo, options))
- retcode = 0;
- }
- /* Point HEAD to the same ref as the remote's head */
- else if (!update_head_to_remote(repo, origin)) {
- retcode = 0;
- }
- }
- }
- git_remote_disconnect(origin);
- }
- git_remote_free(origin);
- }
+ if ((retcode = create_and_configure_origin(&origin, repo, url, options)) < 0)
+ goto on_error;
+
+ git_remote_set_update_fetchhead(origin, 0);
+
+ /* If the download_tags value has not been specified, then make sure to
+ * download tags as well. It is set here because we want to download tags
+ * on the initial clone, but do not want to persist the value in the
+ * configuration file.
+ */
+ if (origin->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_AUTO &&
+ ((retcode = git_remote_add_fetch(origin, "refs/tags/*:refs/tags/*")) < 0))
+ goto on_error;
+
+ /* Connect and download everything */
+ if ((retcode = git_remote_connect(origin, GIT_DIRECTION_FETCH)) < 0)
+ goto on_error;
+ if ((retcode = git_remote_download(origin, options->fetch_progress_cb,
+ options->fetch_progress_payload)) < 0)
+ goto on_error;
+
+ /* Create "origin/foo" branches for all remote branches */
+ if ((retcode = git_remote_update_tips(origin)) < 0)
+ goto on_error;
+
+ /* Point HEAD to the requested branch */
+ if (options->checkout_branch)
+ retcode = update_head_to_branch(repo, options);
+ /* Point HEAD to the same ref as the remote's head */
+ else
+ retcode = update_head_to_remote(repo, origin);
+
+on_error:
+ git_remote_free(origin);
return retcode;
}
@@ -425,7 +435,7 @@ static void normalize_options(git_clone_options *dst, const git_clone_options *s
/* Provide defaults for null pointers */
if (!dst->remote_name) dst->remote_name = "origin";
- if (!dst->remote_autotag) dst->remote_autotag = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
+ if (!dst->remote_autotag) dst->remote_autotag = GIT_REMOTE_DOWNLOAD_TAGS_AUTO;
}
int git_clone(
diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c
index 545fe3a..8b17fd9 100644
--- a/tests-clar/clone/nonetwork.c
+++ b/tests-clar/clone/nonetwork.c
@@ -172,6 +172,7 @@ void test_clone_nonetwork__custom_push_spec(void)
void test_clone_nonetwork__custom_autotag(void)
{
+ git_remote *origin;
git_strarray tags = {0};
g_options.remote_autotag = GIT_REMOTE_DOWNLOAD_TAGS_NONE;
@@ -180,6 +181,23 @@ void test_clone_nonetwork__custom_autotag(void)
cl_git_pass(git_tag_list(&tags, g_repo));
cl_assert_equal_sz(0, tags.count);
+ cl_git_pass(git_remote_load(&origin, g_repo, "origin"));
+ cl_assert_equal_i(GIT_REMOTE_DOWNLOAD_TAGS_NONE, origin->download_tags);
+
+ git_strarray_free(&tags);
+}
+
+void test_clone_nonetwork__custom_autotag_tags_all(void)
+{
+ git_strarray tags = {0};
+ git_remote *origin;
+
+ g_options.remote_autotag = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
+ cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
+
+ cl_git_pass(git_remote_load(&origin, g_repo, "origin"));
+ cl_assert_equal_i(GIT_REMOTE_DOWNLOAD_TAGS_ALL, origin->download_tags);
+
git_strarray_free(&tags);
}
diff --git a/tests-clar/online/clone.c b/tests-clar/online/clone.c
index c1a9a9a..aa12e47 100644
--- a/tests-clar/online/clone.c
+++ b/tests-clar/online/clone.c
@@ -3,6 +3,7 @@
#include "git2/clone.h"
#include "git2/cred_helpers.h"
#include "repository.h"
+#include "remote.h"
#define LIVE_REPO_URL "http://github.com/libgit2/TestGitRepository"
#define LIVE_EMPTYREPO_URL "http://github.com/libgit2/TestEmptyRepository"
@@ -42,6 +43,8 @@ void test_online_clone__network_full(void)
cl_assert(!git_repository_is_bare(g_repo));
cl_git_pass(git_remote_load(&origin, g_repo, "origin"));
+ cl_assert_equal_i(GIT_REMOTE_DOWNLOAD_TAGS_AUTO, origin->download_tags);
+
git_remote_free(origin);
}