Include checkout options inline
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
diff --git a/examples/network/clone.c b/examples/network/clone.c
index 2bfad44..9b323ff 100644
--- a/examples/network/clone.c
+++ b/examples/network/clone.c
@@ -94,10 +94,10 @@ int do_clone(git_repository *repo, int argc, char **argv)
}
// Set up options
- clone_opts.checkout_opts = &checkout_opts;
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
checkout_opts.progress_cb = checkout_progress;
checkout_opts.progress_payload = &pd;
+ clone_opts.checkout_opts = checkout_opts;
clone_opts.fetch_progress_cb = &fetch_progress;
clone_opts.fetch_progress_payload = &pd;
clone_opts.cred_acquire_cb = cred_acquire;
diff --git a/include/git2/clone.h b/include/git2/clone.h
index 72fba0e..c6ab803 100644
--- a/include/git2/clone.h
+++ b/include/git2/clone.h
@@ -31,14 +31,14 @@ GIT_BEGIN_DECL
*
* git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
*
+ * - `checkout_opts` is options for the checkout step. To disable checkout,
+ * 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
- * - `checkout_opts` is options for the checkout step. If NULL, no checkout is
- * performed
*
* ** "origin" remote options: **
* - `remote_name` is the name given to the "origin" remote. The default is
@@ -62,10 +62,10 @@ GIT_BEGIN_DECL
typedef struct git_clone_options {
unsigned int version;
+ git_checkout_opts checkout_opts;
int bare;
git_transfer_progress_callback fetch_progress_cb;
void *fetch_progress_payload;
- git_checkout_opts *checkout_opts;
const char *remote_name;
const char *pushurl;
@@ -79,7 +79,7 @@ typedef struct git_clone_options {
} git_clone_options;
#define GIT_CLONE_OPTIONS_VERSION 1
-#define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION}
+#define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION, {GIT_CHECKOUT_OPTS_VERSION, GIT_CHECKOUT_SAFE}}
/**
* Clone a remote repository, and checkout the branch pointed to by the remote
diff --git a/src/clone.c b/src/clone.c
index 9c4a5d9..39c0ba2 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -362,6 +362,9 @@ static bool should_checkout(
if (!opts)
return false;
+ if (opts->checkout_strategy == GIT_CHECKOUT_DEFAULT)
+ return false;
+
return !git_repository_head_orphan(repo);
}
@@ -406,8 +409,8 @@ int git_clone(
}
}
- if (!retcode && should_checkout(repo, normOptions.bare, normOptions.checkout_opts))
- retcode = git_checkout_head(*out, normOptions.checkout_opts);
+ if (!retcode && should_checkout(repo, normOptions.bare, &normOptions.checkout_opts))
+ retcode = git_checkout_head(*out, &normOptions.checkout_opts);
return retcode;
}
diff --git a/tests-clar/clone/network.c b/tests-clar/clone/network.c
index 154fbe8..8850987 100644
--- a/tests-clar/clone/network.c
+++ b/tests-clar/clone/network.c
@@ -13,10 +13,14 @@ static git_clone_options g_options;
void test_clone_network__initialize(void)
{
+ git_checkout_opts dummy_opts = GIT_CHECKOUT_OPTS_INIT;
+
g_repo = NULL;
memset(&g_options, 0, sizeof(git_clone_options));
g_options.version = GIT_CLONE_OPTIONS_VERSION;
+ g_options.checkout_opts = dummy_opts;
+ g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
}
static void cleanup_repository(void *path)
@@ -88,6 +92,7 @@ void test_clone_network__can_prevent_the_checkout_of_a_standard_repo(void)
git_buf path = GIT_BUF_INIT;
cl_set_cleanup(&cleanup_repository, "./foo");
+ g_options.checkout_opts.checkout_strategy = 0;
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt"));
@@ -112,16 +117,14 @@ static void fetch_progress(const git_transfer_progress *stats, void *payload)
void test_clone_network__can_checkout_a_cloned_repo(void)
{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
git_buf path = GIT_BUF_INIT;
git_reference *head;
bool checkout_progress_cb_was_called = false,
fetch_progress_cb_was_called = false;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE;
- opts.progress_cb = &checkout_progress;
- opts.progress_payload = &checkout_progress_cb_was_called;
- g_options.checkout_opts = &opts;
+ g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+ g_options.checkout_opts.progress_cb = &checkout_progress;
+ g_options.checkout_opts.progress_payload = &checkout_progress_cb_was_called;
g_options.fetch_progress_cb = &fetch_progress;
g_options.fetch_progress_payload = &fetch_progress_cb_was_called;
diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c
index 9196803..51fedab 100644
--- a/tests-clar/clone/nonetwork.c
+++ b/tests-clar/clone/nonetwork.c
@@ -10,10 +10,14 @@ static git_repository *g_repo;
void test_clone_nonetwork__initialize(void)
{
+ git_checkout_opts dummy_opts = GIT_CHECKOUT_OPTS_INIT;
+
g_repo = NULL;
memset(&g_options, 0, sizeof(git_clone_options));
g_options.version = GIT_CLONE_OPTIONS_VERSION;
+ g_options.checkout_opts = dummy_opts;
+ g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
}
static void cleanup_repository(void *path)