Skip to content

Expose refspecs in git_clone_opts #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/git2/clone.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/libgit2/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down Expand Up @@ -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;

Expand Down
Loading