Skip to content

Commit 78fde8c

Browse files
authored
Expose refspecs in git_clone_opts
1 parent 402a587 commit 78fde8c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

include/git2/clone.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ typedef struct git_clone_options {
161161
* This parameter is ignored unless remote_cb is non-NULL.
162162
*/
163163
void *remote_cb_payload;
164+
165+
/*
166+
* The refspecs to use for the clone. If empty, all refs will be cloned.
167+
* example: {"main:main", "HEAD"}
168+
*/
169+
git_strarray refspecs;
164170
} git_clone_options;
165171

166172
#define GIT_CLONE_OPTIONS_VERSION 1

src/libgit2/clone.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c
393393
return error;
394394
}
395395

396-
static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch_options *opts, const git_checkout_options *co_opts, const char *branch)
396+
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)
397397
{
398398
int error;
399399
git_str reflog_message = GIT_STR_INIT;
@@ -416,7 +416,7 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch
416416
fetch_opts.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
417417
git_str_printf(&reflog_message, "clone: from %s", git_remote_url(remote));
418418

419-
if ((error = git_remote_fetch(remote, NULL, &fetch_opts, git_str_cstr(&reflog_message))) != 0)
419+
if ((error = git_remote_fetch(remote, refspecs, &fetch_opts, git_str_cstr(&reflog_message))) != 0)
420420
goto cleanup;
421421

422422
error = checkout_branch(repo, remote, co_opts, branch, git_str_cstr(&reflog_message));
@@ -507,7 +507,7 @@ static int git__clone(
507507
else if (clone_local == 0)
508508
error = clone_into(
509509
repo, origin, &options.fetch_opts, &options.checkout_opts,
510-
options.checkout_branch);
510+
options.checkout_branch, options.refspecs.count == 0 ? NULL : &options.refspecs);
511511
else
512512
error = -1;
513513

0 commit comments

Comments
 (0)