summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2022-03-01 10:08:41 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2022-03-23 08:35:59 -0400
commit2a827f80474d74ba7d145afeb0fc0795282fabc4 (patch)
tree8237bb23edf9451646fe755f38431845d3786112
parent782b8945b0809d268da792c4fb250846d91b6255 (diff)
downloadlibgit2-2a827f80474d74ba7d145afeb0fc0795282fabc4.tar.gz
clone: introduce `no_checkout` option
Using `GIT_CHECKOUT_NONE` as an indication that we shouldn't checkout during clone saves options(!) but is a very leaky abstraction. `git_checkout` shouldn't have an idea of being invoked just to do nothing (why would somebody invoke it then?); instead we should teach clone not to do the checkout.
-rw-r--r--include/git2/clone.h6
-rw-r--r--src/libgit2/clone.c6
-rw-r--r--src/libgit2/submodule.c2
3 files changed, 10 insertions, 4 deletions
diff --git a/include/git2/clone.h b/include/git2/clone.h
index ad11120bc..adf8e5536 100644
--- a/include/git2/clone.h
+++ b/include/git2/clone.h
@@ -105,8 +105,7 @@ typedef struct git_clone_options {
/**
* These options are passed to the checkout step. To disable
- * checkout, set the `checkout_strategy` to
- * `GIT_CHECKOUT_DRY_RUN`.
+ * checkout, set the `no_checkout` option to `1`.
*/
git_checkout_options checkout_opts;
@@ -118,6 +117,9 @@ typedef struct git_clone_options {
*/
git_fetch_options fetch_opts;
+ /** Set to non-zero to not check out the working directory. */
+ int no_checkout;
+
/**
* Set to zero (false) to create a standard repo, or non-zero
* for a bare repo
diff --git a/src/libgit2/clone.c b/src/libgit2/clone.c
index bec8dc459..c872000d0 100644
--- a/src/libgit2/clone.c
+++ b/src/libgit2/clone.c
@@ -363,7 +363,7 @@ static bool should_checkout(
if (is_bare)
return false;
- if (opts->checkout_opts.checkout_strategy == GIT_CHECKOUT_NONE)
+ if (opts->no_checkout)
return false;
return !git_repository_head_unborn(repo);
@@ -582,6 +582,10 @@ static int clone_repo(
options.fetch_opts.update_fetchhead = 0;
options.fetch_opts.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
+ /* Backward compatibility: support the deprecated GIT_CHECKOUT_NONE */
+ if (options.checkout_opts.checkout_strategy == GIT_CHECKOUT_NONE)
+ options.no_checkout = 1;
+
/* Only clone to a new directory or an empty directory */
if (git_fs_path_exists(local_path) && !use_existing && !git_fs_path_is_empty_dir(local_path)) {
git_error_set(GIT_ERROR_INVALID,
diff --git a/src/libgit2/submodule.c b/src/libgit2/submodule.c
index 0f4f0726c..94c089b89 100644
--- a/src/libgit2/submodule.c
+++ b/src/libgit2/submodule.c
@@ -1387,7 +1387,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
* Do not perform checkout as part of clone, instead we
* will checkout the specific commit manually.
*/
- clone_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_NONE;
+ clone_options.no_checkout = 1;
if ((error = git_clone(&sub_repo, submodule_url, sm->path, &clone_options)) < 0 ||
(error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm))) < 0 ||