mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-23 12:05:21 +00:00
Include checkout options inline
This commit is contained in:
parent
c07b52df1b
commit
730df6d0f7
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user