Skip to content

Commit 2fe8c11

Browse files
Merge pull request #526 from pallan/remote-prune
Adds Rugged::Remote#fetch(prune:)
2 parents 3267567 + df55e07 commit 2fe8c11

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

ext/rugged/rugged_remote.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ void rugged_remote_init_callbacks_and_payload_from_options(
181181
}
182182
}
183183

184+
static int parse_prune_type(VALUE rb_prune_type)
185+
{
186+
if (rb_prune_type == Qtrue) {
187+
return GIT_FETCH_PRUNE;
188+
} else if (rb_prune_type == Qfalse) {
189+
return GIT_FETCH_NO_PRUNE;
190+
} else if (rb_prune_type == Qnil) {
191+
return GIT_FETCH_PRUNE_UNSPECIFIED;
192+
} else {
193+
rb_raise(rb_eTypeError, "wrong argument type for :prune (expected true, false or nil)");
194+
}
195+
}
196+
184197
static void rb_git_remote__free(git_remote *remote)
185198
{
186199
git_remote_free(remote);
@@ -502,6 +515,10 @@ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
502515
* :message ::
503516
* The message to insert into the reflogs. Defaults to "fetch".
504517
*
518+
* :prune ::
519+
* Specifies the prune mode for the fetch. +true+ remove any remote-tracking references that
520+
* no longer exist, +false+ do not prune, +nil+ use configured settings Defaults to "nil".
521+
*
505522
* Example:
506523
*
507524
* remote = Rugged::Remote.lookup(@repo, 'origin')
@@ -536,6 +553,9 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
536553
VALUE rb_val = rb_hash_aref(rb_options, CSTR2SYM("message"));
537554
if (!NIL_P(rb_val))
538555
log_message = StringValueCStr(rb_val);
556+
557+
VALUE rb_prune_type = rb_hash_aref(rb_options, CSTR2SYM("prune"));
558+
opts.prune = parse_prune_type(rb_prune_type);
539559
}
540560

541561
error = git_remote_fetch(remote, &refspecs, &opts, log_message);

test/remote_test.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,50 @@ def test_push_non_forward_forced_raise_no_error
168168

169169
assert_equal "8496071c1b46c854b31185ea97743be6a8774479", @remote_repo.ref("refs/heads/master").target_id
170170
end
171+
172+
end
173+
174+
class RemotePruneTest < Rugged::TestCase
175+
def setup
176+
@remote_repo = FixtureRepo.from_libgit2("testrepo.git")
177+
# We can only push to bare repos
178+
@remote_repo.config['core.bare'] = 'true'
179+
180+
@repo = FixtureRepo.clone(@remote_repo)
181+
@repo.references.create("refs/heads/unit_test", "8496071c1b46c854b31185ea97743be6a8774479")
182+
183+
@remote = @repo.remotes['origin']
184+
185+
@remote.push(["refs/heads/unit_test"])
186+
@remote_repo.references.delete("refs/heads/unit_test")
187+
end
188+
189+
def test_fetch_prune_is_forced
190+
assert_equal "8496071c1b46c854b31185ea97743be6a8774479", @repo.ref("refs/remotes/origin/unit_test").target_id
191+
@remote.fetch(prune: true)
192+
assert_nil @repo.ref("refs/remotes/origin/unit_test")
193+
end
194+
195+
def test_fetch_prune_is_not_forced
196+
@remote.fetch(prune: false)
197+
assert_equal "8496071c1b46c854b31185ea97743be6a8774479", @repo.ref("refs/remotes/origin/unit_test").target_id
198+
end
199+
200+
def test_fetch_prune_nil
201+
@remote.fetch(prune: nil)
202+
assert_equal "8496071c1b46c854b31185ea97743be6a8774479", @repo.ref("refs/remotes/origin/unit_test").target_id
203+
end
204+
205+
def test_fetch_prune_nil
206+
@remote.fetch(prune: nil)
207+
assert_equal "8496071c1b46c854b31185ea97743be6a8774479", @repo.ref("refs/remotes/origin/unit_test").target_id
208+
end
209+
210+
def test_fetch_prune_with_invalid_argument_raises
211+
assert_raises TypeError do
212+
@remote.fetch(prune: 'INVALID')
213+
end
214+
end
171215
end
172216

173217
class RemoteWriteTest < Rugged::TestCase

0 commit comments

Comments
 (0)