Skip to content

Commit 0772a8e

Browse files
authored
Merge pull request #980 from Bo98/fetch-depth
Support setting fetch depth
2 parents 49bd976 + 97d1a12 commit 0772a8e

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

ext/rugged/rugged.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ struct rugged_remote_cb_payload
185185
int exception;
186186
};
187187

188+
void rugged_remote_init_fetch_options(VALUE rb_options, git_fetch_options *fetch_options);
189+
188190
void rugged_remote_init_custom_headers(VALUE rb_options, git_strarray *custom_headers);
189191

190192
void rugged_remote_init_proxy_options(VALUE rb_options, git_proxy_options *proxy_options);

ext/rugged/rugged_remote.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,21 @@ static int credentials_cb(
159159
return payload->exception ? GIT_ERROR : GIT_OK;
160160
}
161161

162+
void rugged_remote_init_fetch_options(VALUE rb_options, git_fetch_options *fetch_options)
163+
{
164+
rugged_remote_init_custom_headers(rb_options, &fetch_options->custom_headers);
165+
rugged_remote_init_proxy_options(rb_options, &fetch_options->proxy_opts);
166+
167+
if (!NIL_P(rb_options))
168+
{
169+
VALUE depth = rb_hash_aref(rb_options, CSTR2SYM("depth"));
170+
if (!NIL_P(depth)) {
171+
Check_Type(depth, T_FIXNUM);
172+
fetch_options->depth = FIX2UINT(depth);
173+
}
174+
}
175+
}
176+
162177
void rugged_remote_init_callbacks_and_payload_from_options(
163178
VALUE rb_options,
164179
git_remote_callbacks *callbacks,
@@ -639,8 +654,7 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
639654
TypedData_Get_Struct(self, git_remote, &rugged_remote_type, remote);
640655

641656
rugged_remote_init_callbacks_and_payload_from_options(rb_options, &opts.callbacks, &payload);
642-
rugged_remote_init_custom_headers(rb_options, &opts.custom_headers);
643-
rugged_remote_init_proxy_options(rb_options, &opts.proxy_opts);
657+
rugged_remote_init_fetch_options(rb_options, &opts);
644658

645659
if (!NIL_P(rb_options)) {
646660
VALUE rb_prune_type;

ext/rugged/rugged_repo.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,7 @@ static void parse_clone_options(git_clone_options *ret, VALUE rb_options, struct
542542
}
543543

544544
rugged_remote_init_callbacks_and_payload_from_options(rb_options, &ret->fetch_opts.callbacks, remote_payload);
545-
rugged_remote_init_custom_headers(rb_options, &ret->fetch_opts.custom_headers);
546-
rugged_remote_init_proxy_options(rb_options, &ret->fetch_opts.proxy_opts);
545+
rugged_remote_init_fetch_options(rb_options, &ret->fetch_opts);
547546
}
548547

549548
/*

test/online/fetch_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ def test_fetch_over_https_with_certificate_callback_exception
7979
assert_equal "Exception from callback", exception.message
8080
end
8181

82+
def test_fetch_over_https_shallow
83+
skip unless Rugged.features.include?(:https)
84+
85+
@repo.remotes.create("origin", "https://github.com/libgit2/TestGitRepository.git")
86+
87+
@repo.fetch("origin", :depth => 1)
88+
89+
assert @repo.shallow?
90+
end
91+
8292
def test_fetch_over_ssh_with_credentials
8393
skip unless Rugged.features.include?(:ssh) && ssh_creds?
8494

0 commit comments

Comments
 (0)