diff --git a/include/git2/clone.h b/include/git2/clone.h index 3481f254c9d..ae51e633b7b 100644 --- a/include/git2/clone.h +++ b/include/git2/clone.h @@ -161,6 +161,12 @@ typedef struct git_clone_options { * This parameter is ignored unless remote_cb is non-NULL. */ void *remote_cb_payload; + + /* + * The refspecs to use for the clone. If empty, all refs will be cloned. + * example: {"main:main", "HEAD"} + */ + git_strarray refspecs; } git_clone_options; #define GIT_CLONE_OPTIONS_VERSION 1 diff --git a/src/libgit2/clone.c b/src/libgit2/clone.c index 0d393eb858a..9aadb0f17a7 100644 --- a/src/libgit2/clone.c +++ b/src/libgit2/clone.c @@ -393,7 +393,7 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c return error; } -static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch_options *opts, const git_checkout_options *co_opts, const char *branch) +static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch_options *opts, const git_checkout_options *co_opts, const char *branch, const git_strarray *refspecs) { int error; git_str reflog_message = GIT_STR_INIT; @@ -416,7 +416,7 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch fetch_opts.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL; git_str_printf(&reflog_message, "clone: from %s", git_remote_url(remote)); - if ((error = git_remote_fetch(remote, NULL, &fetch_opts, git_str_cstr(&reflog_message))) != 0) + if ((error = git_remote_fetch(remote, refspecs, &fetch_opts, git_str_cstr(&reflog_message))) != 0) goto cleanup; error = checkout_branch(repo, remote, co_opts, branch, git_str_cstr(&reflog_message)); @@ -507,7 +507,7 @@ static int git__clone( else if (clone_local == 0) error = clone_into( repo, origin, &options.fetch_opts, &options.checkout_opts, - options.checkout_branch); + options.checkout_branch, options.refspecs.count == 0 ? NULL : &options.refspecs); else error = -1;