From b11e9938475a9e2cc57fcfccc0d180b53f0e69f9 Mon Sep 17 00:00:00 2001 From: Christoph Bartschat Date: Mon, 11 Nov 2024 16:23:36 -0800 Subject: [PATCH 1/2] Expose refspecs in git_clone_opts --- include/git2/clone.h | 5 +++++ src/libgit2/clone.c | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/git2/clone.h b/include/git2/clone.h index 3481f254c9d..23a1fb5c96e 100644 --- a/include/git2/clone.h +++ b/include/git2/clone.h @@ -161,6 +161,11 @@ 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. + */ + 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; From bb11af675556c16e394b75c1c0915a848b1c4488 Mon Sep 17 00:00:00 2001 From: Christoph Bartschat Date: Mon, 11 Nov 2024 16:24:40 -0800 Subject: [PATCH 2/2] Expose refspecs in git_clone_opts --- include/git2/clone.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/git2/clone.h b/include/git2/clone.h index 23a1fb5c96e..ae51e633b7b 100644 --- a/include/git2/clone.h +++ b/include/git2/clone.h @@ -164,6 +164,7 @@ typedef struct git_clone_options { /* * The refspecs to use for the clone. If empty, all refs will be cloned. + * example: {"main:main", "HEAD"} */ git_strarray refspecs; } git_clone_options;