Skip to content

Commit

Permalink
Expose refspecs in git_clone_opts
Browse files Browse the repository at this point in the history
  • Loading branch information
cmbartschat authored Nov 12, 2024
1 parent 402a587 commit 78fde8c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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

0 comments on commit 78fde8c

Please sign in to comment.