Skip to content

Commit c937735

Browse files
Expose rugged exception handling.
1 parent b4978cf commit c937735

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

ext/rugged/rugged.c

+8
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ void rugged_exception_raise(void)
346346
rb_exc_raise(err_obj);
347347
}
348348

349+
VALUE rb_git_raise_exception(VALUE self)
350+
{
351+
rugged_exception_raise();
352+
return Qnil;
353+
}
354+
349355
VALUE rugged__block_yield_splat(VALUE args) {
350356
VALUE block = rb_ary_shift(args);
351357
int n = RARRAY_LENINT(args);
@@ -451,6 +457,8 @@ void Init_rugged(void)
451457
rb_define_module_function(rb_mRugged, "prettify_message", rb_git_prettify_message, -1);
452458
rb_define_module_function(rb_mRugged, "__cache_usage__", rb_git_cache_usage, 0);
453459

460+
rb_define_private_method(rb_singleton_class(rb_mRugged), "__raise_exception__", rb_git_raise_exception, 0);
461+
454462
Init_rugged_reference();
455463
Init_rugged_reference_collection();
456464

test/lib_test.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ def test_libgit2_version
1818
end
1919
end
2020

21+
def test_raise_exception
22+
# Ensure libgit2 error state is cleared
23+
Rugged.send(:__raise_exception__) rescue nil
24+
25+
err = assert_raises(RuntimeError) { Rugged.send(:__raise_exception__) }
26+
assert_equal "Rugged operation failed", err.message
27+
end
28+
2129
def test_options
2230
Rugged::Settings['mwindow_size'] = 8 * 1024 * 1024
2331
Rugged::Settings['mwindow_mapped_limit'] = 8 * 1024 * 1024
@@ -141,4 +149,3 @@ def test_prettify_commit_messages
141149
assert_equal clean_message, Rugged::prettify_message(message, true)
142150
end
143151
end
144-

0 commit comments

Comments
 (0)