Commit 730df6d0 by Ben Straub

Include checkout options inline

parent c07b52df
...@@ -94,10 +94,10 @@ int do_clone(git_repository *repo, int argc, char **argv) ...@@ -94,10 +94,10 @@ int do_clone(git_repository *repo, int argc, char **argv)
} }
// Set up options // Set up options
clone_opts.checkout_opts = &checkout_opts;
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE; checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
checkout_opts.progress_cb = checkout_progress; checkout_opts.progress_cb = checkout_progress;
checkout_opts.progress_payload = &pd; checkout_opts.progress_payload = &pd;
clone_opts.checkout_opts = checkout_opts;
clone_opts.fetch_progress_cb = &fetch_progress; clone_opts.fetch_progress_cb = &fetch_progress;
clone_opts.fetch_progress_payload = &pd; clone_opts.fetch_progress_payload = &pd;
clone_opts.cred_acquire_cb = cred_acquire; clone_opts.cred_acquire_cb = cred_acquire;
......
...@@ -31,14 +31,14 @@ GIT_BEGIN_DECL ...@@ -31,14 +31,14 @@ GIT_BEGIN_DECL
* *
* git_clone_options opts = GIT_CLONE_OPTIONS_INIT; * 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 * - `bare` should be set to zero to create a standard repo, non-zero for
* a bare repo * a bare repo
* - `fetch_progress_cb` is optional callback for fetch progress. Be aware that * - `fetch_progress_cb` is optional callback for fetch progress. Be aware that
* this is called inline with network and indexing operations, so performance * this is called inline with network and indexing operations, so performance
* may be affected. * may be affected.
* - `fetch_progress_payload` is payload for fetch_progress_cb * - `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: ** * ** "origin" remote options: **
* - `remote_name` is the name given to the "origin" remote. The default is * - `remote_name` is the name given to the "origin" remote. The default is
...@@ -62,10 +62,10 @@ GIT_BEGIN_DECL ...@@ -62,10 +62,10 @@ GIT_BEGIN_DECL
typedef struct git_clone_options { typedef struct git_clone_options {
unsigned int version; unsigned int version;
git_checkout_opts checkout_opts;
int bare; int bare;
git_transfer_progress_callback fetch_progress_cb; git_transfer_progress_callback fetch_progress_cb;
void *fetch_progress_payload; void *fetch_progress_payload;
git_checkout_opts *checkout_opts;
const char *remote_name; const char *remote_name;
const char *pushurl; const char *pushurl;
...@@ -79,7 +79,7 @@ typedef struct git_clone_options { ...@@ -79,7 +79,7 @@ typedef struct git_clone_options {
} git_clone_options; } git_clone_options;
#define GIT_CLONE_OPTIONS_VERSION 1 #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 * Clone a remote repository, and checkout the branch pointed to by the remote
......
...@@ -362,6 +362,9 @@ static bool should_checkout( ...@@ -362,6 +362,9 @@ static bool should_checkout(
if (!opts) if (!opts)
return false; return false;
if (opts->checkout_strategy == GIT_CHECKOUT_DEFAULT)
return false;
return !git_repository_head_orphan(repo); return !git_repository_head_orphan(repo);
} }
...@@ -406,8 +409,8 @@ int git_clone( ...@@ -406,8 +409,8 @@ int git_clone(
} }
} }
if (!retcode && should_checkout(repo, normOptions.bare, normOptions.checkout_opts)) if (!retcode && should_checkout(repo, normOptions.bare, &normOptions.checkout_opts))
retcode = git_checkout_head(*out, normOptions.checkout_opts); retcode = git_checkout_head(*out, &normOptions.checkout_opts);
return retcode; return retcode;
} }
...@@ -13,10 +13,14 @@ static git_clone_options g_options; ...@@ -13,10 +13,14 @@ static git_clone_options g_options;
void test_clone_network__initialize(void) void test_clone_network__initialize(void)
{ {
git_checkout_opts dummy_opts = GIT_CHECKOUT_OPTS_INIT;
g_repo = NULL; g_repo = NULL;
memset(&g_options, 0, sizeof(git_clone_options)); memset(&g_options, 0, sizeof(git_clone_options));
g_options.version = GIT_CLONE_OPTIONS_VERSION; 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) static void cleanup_repository(void *path)
...@@ -88,6 +92,7 @@ void test_clone_network__can_prevent_the_checkout_of_a_standard_repo(void) ...@@ -88,6 +92,7 @@ void test_clone_network__can_prevent_the_checkout_of_a_standard_repo(void)
git_buf path = GIT_BUF_INIT; git_buf path = GIT_BUF_INIT;
cl_set_cleanup(&cleanup_repository, "./foo"); 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_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options));
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "master.txt")); 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) ...@@ -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) 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_buf path = GIT_BUF_INIT;
git_reference *head; git_reference *head;
bool checkout_progress_cb_was_called = false, bool checkout_progress_cb_was_called = false,
fetch_progress_cb_was_called = false; fetch_progress_cb_was_called = false;
opts.checkout_strategy = GIT_CHECKOUT_SAFE; g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
opts.progress_cb = &checkout_progress; g_options.checkout_opts.progress_cb = &checkout_progress;
opts.progress_payload = &checkout_progress_cb_was_called; g_options.checkout_opts.progress_payload = &checkout_progress_cb_was_called;
g_options.checkout_opts = &opts;
g_options.fetch_progress_cb = &fetch_progress; g_options.fetch_progress_cb = &fetch_progress;
g_options.fetch_progress_payload = &fetch_progress_cb_was_called; g_options.fetch_progress_payload = &fetch_progress_cb_was_called;
......
...@@ -10,10 +10,14 @@ static git_repository *g_repo; ...@@ -10,10 +10,14 @@ static git_repository *g_repo;
void test_clone_nonetwork__initialize(void) void test_clone_nonetwork__initialize(void)
{ {
git_checkout_opts dummy_opts = GIT_CHECKOUT_OPTS_INIT;
g_repo = NULL; g_repo = NULL;
memset(&g_options, 0, sizeof(git_clone_options)); memset(&g_options, 0, sizeof(git_clone_options));
g_options.version = GIT_CLONE_OPTIONS_VERSION; 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) static void cleanup_repository(void *path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment