Skip to content
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

Support setting fetch depth #980

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions ext/rugged/rugged.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ struct rugged_remote_cb_payload
int exception;
};

void rugged_remote_init_fetch_options(VALUE rb_options, git_fetch_options *fetch_options);

void rugged_remote_init_custom_headers(VALUE rb_options, git_strarray *custom_headers);

void rugged_remote_init_proxy_options(VALUE rb_options, git_proxy_options *proxy_options);
Expand Down
18 changes: 16 additions & 2 deletions ext/rugged/rugged_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ static int credentials_cb(
return payload->exception ? GIT_ERROR : GIT_OK;
}

void rugged_remote_init_fetch_options(VALUE rb_options, git_fetch_options *fetch_options)
{
rugged_remote_init_custom_headers(rb_options, &fetch_options->custom_headers);
rugged_remote_init_proxy_options(rb_options, &fetch_options->proxy_opts);

if (!NIL_P(rb_options))
{
VALUE depth = rb_hash_aref(rb_options, CSTR2SYM("depth"));
if (!NIL_P(depth)) {
Check_Type(depth, T_FIXNUM);
fetch_options->depth = FIX2UINT(depth);
}
}
}

void rugged_remote_init_callbacks_and_payload_from_options(
VALUE rb_options,
git_remote_callbacks *callbacks,
Expand Down Expand Up @@ -628,8 +643,7 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
Data_Get_Struct(self, git_remote, remote);

rugged_remote_init_callbacks_and_payload_from_options(rb_options, &opts.callbacks, &payload);
rugged_remote_init_custom_headers(rb_options, &opts.custom_headers);
rugged_remote_init_proxy_options(rb_options, &opts.proxy_opts);
rugged_remote_init_fetch_options(rb_options, &opts);

if (!NIL_P(rb_options)) {
VALUE rb_prune_type;
Expand Down
3 changes: 1 addition & 2 deletions ext/rugged/rugged_repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,7 @@ static void parse_clone_options(git_clone_options *ret, VALUE rb_options, struct
}

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);
rugged_remote_init_fetch_options(rb_options, &ret->fetch_opts);
}

/*
Expand Down
10 changes: 10 additions & 0 deletions test/online/fetch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ def test_fetch_over_https_with_certificate_callback_exception
assert_equal "Exception from callback", exception.message
end

def test_fetch_over_https_shallow
skip unless Rugged.features.include?(:https)

@repo.remotes.create("origin", "https://github.com/libgit2/TestGitRepository.git")

@repo.fetch("origin", :depth => 1)

assert @repo.shallow?
end

def test_fetch_over_ssh_with_credentials
skip unless Rugged.features.include?(:ssh) && ssh_creds?

Expand Down