Skip to content

Ability to pass options to clone? #295

Closed
@benbalter

Description

@benbalter

Wondering if it's possible to pass options to the clone action, specifically --recursive and --depth=1

Here's what I've got:

repo = Rugged::Repository.clone_at @git_url, @source, { :branch => @git_ref, :recursive => true, :depth => 1 }

Activity

arrbee

arrbee commented on Dec 2, 2013

@arrbee
Member

@benbalter Currently, the underlying libgit2 code doesn't support making shallow clones nor does it support recursive submodule updates. Using the submodule APIs, it would probably be possible to implement the equivalent of --recursive but I don't think the necessary APIs are currently available in Rugged. I'm pretty sure there is no way to do a shallow clone at all without changes to the libgit2.

benbalter

benbalter commented on Dec 3, 2013

@benbalter
Author

Le sad. Thanks for the prompt response.

carlosmn

carlosmn commented on Dec 3, 2013

@carlosmn
Member

Shallow fetches/clones are a mess and still a hack. There is currently an attempt at making them better-defined, but the odd repos that result are a mess and still have many limitations even with git-core.

While not as fast to type, you do have a programming language available, which makes automatic recursive submodule initialisation less of an advantage. It's probably enough of a promiment git-core feature that it will have to be implemented at some point.

arrbee

arrbee commented on Dec 3, 2013

@arrbee
Member

Thanks for clarifying @carlosmn - you're right (as always). I do have it on my TODO list to add recursive submodule support to libgit2 checkout and clone, but it hasn't been too high up there. Still, probably a good thing to get to and not too hard, I think.

ben

ben commented on Dec 3, 2013

@ben
Member

Better shallow-repo support is on my list, but the concepts are tangled up with alternates and grafts, and it could get a little hairy.

added this to the libgit2 milestone on Apr 23, 2014
dideler

dideler commented on Feb 17, 2016

@dideler

FWIW, related libgit2 issue is libgit2/libgit2#3058

kjetilho

kjetilho commented on Dec 27, 2023

@kjetilho

libgit2 added shallow support in version 1.7.0 (July 2023)

benbalter

benbalter commented on Dec 28, 2023

@benbalter
Author

libgit2 added shallow support in version 1.7.0 (July 2023)

Thanks for updating this ancient issue. Marking as resolved.

kjetilho

kjetilho commented on Dec 28, 2023

@kjetilho

libgit2 added shallow support in version 1.7.0 (July 2023)

Thanks for updating this ancient issue. Marking as resolved.

hmm, but I don't see how Rugged allows me to pass a value for depth to fetch?

Bo98

Bo98 commented on May 23, 2024

@Bo98

I don't see how Rugged allows me to pass a value for depth to fetch?

#980 should address this

heyvito

heyvito commented on Dec 12, 2024

@heyvito

I think this issue should still be open as #980 has not been merged.

The following snippet is way slower than running git clone --depth 1:

Rugged::Repository.clone_at(source, dir, credentials:, depth: 1)

Option is not being handled by

/*
* call-seq:
* Repository.clone_at(url, local_path[, options]) -> repository
*
* Clone a repository from +url+ to +local_path+.
*
* The following options can be passed in the +options+ Hash:
*
* :bare ::
* If +true+, the clone will be created as a bare repository.
* Defaults to +false+.
*
* :checkout_branch ::
* The name of a branch to checkout. Defaults to the remote's +HEAD+.
*
* :remote ::
* The name to give to the "origin" remote. Defaults to <tt>"origin"</tt>.
*
* :ignore_cert_errors ::
* If set to +true+, errors while validating the remote's host certificate will be ignored.
*
* :proxy_url ::
* The url of an http proxy to use to access the remote repository.
*
* :credentials ::
* The credentials to use for the clone operation. Can be either an instance of one
* of the Rugged::Credentials types, or a proc returning one of the former.
* The proc will be called with the +url+, the +username+ from the url (if applicable) and
* a list of applicable credential types.
*
* :progress ::
* A callback that will be executed with the textual progress received from the remote.
* This is the text send over the progress side-band (ie. the "counting objects" output).
*
* :transfer_progress ::
* A callback that will be executed to report clone progress information. It will be passed
* the amount of +total_objects+, +indexed_objects+, +received_objects+, +local_objects+,
* +total_deltas+, +indexed_deltas+, and +received_bytes+.
*
* :update_tips ::
* A callback that will be executed each time a reference was updated locally. It will be
* passed the +refname+, +old_oid+ and +new_oid+.
*
* Example:
*
* Repository.clone_at("https://github.com/libgit2/rugged.git", "./some/dir", {
* transfer_progress: lambda { |total_objects, indexed_objects, received_objects, local_objects, total_deltas, indexed_deltas, received_bytes|
* # ...
* }
* })
*/
static VALUE rb_git_repo_clone_at(int argc, VALUE *argv, VALUE klass)
{
VALUE url, local_path, rb_options_hash;
git_clone_options options = GIT_CLONE_OPTIONS_INIT;
struct rugged_remote_cb_payload remote_payload = { Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, 0 };
git_repository *repo;
int error;
rb_scan_args(argc, argv, "21", &url, &local_path, &rb_options_hash);
Check_Type(url, T_STRING);
FilePathValue(local_path);
parse_clone_options(&options, rb_options_hash, &remote_payload);
error = git_clone(&repo, StringValueCStr(url), StringValueCStr(local_path), &options);
if (RTEST(remote_payload.exception))
rb_jump_tag(remote_payload.exception);
rugged_exception_check(error);
return rugged_repo_new(klass, repo);
}

and

static void parse_clone_options(git_clone_options *ret, VALUE rb_options, struct rugged_remote_cb_payload *remote_payload)
{
VALUE val;
if (NIL_P(rb_options))
return;
val = rb_hash_aref(rb_options, CSTR2SYM("bare"));
if (RTEST(val))
ret->bare = 1;
val = rb_hash_aref(rb_options, CSTR2SYM("checkout_branch"));
if (!NIL_P(val)) {
Check_Type(val, T_STRING);
ret->checkout_branch = StringValueCStr(val);
}
rugged_remote_init_callbacks_and_payload_from_options(rb_options, &ret->fetch_opts.callbacks, remote_payload);
rugged_remote_init_custom_headers(rb_options, &ret->fetch_opts.custom_headers);
rugged_remote_init_proxy_options(rb_options, &ret->fetch_opts.proxy_opts);
}

bwitt

bwitt commented on May 12, 2025

@bwitt

sounds like this issue should still be open, as #980 is not merged. @benbalter what do you think?

bwitt

bwitt commented on May 15, 2025

@bwitt

@carlosmn would you be able to reopen this? this is not yet resolved (needs #980 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @arthurschreiber@ben@heyvito@arrbee@benbalter

      Issue actions

        Ability to pass options to clone? · Issue #295 · libgit2/rugged