Skip to content

Commit

Permalink
Expose rugged exception handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurschreiber committed Oct 13, 2015
1 parent b4978cf commit c937735
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ext/rugged/rugged.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ void rugged_exception_raise(void)
rb_exc_raise(err_obj);
}

VALUE rb_git_raise_exception(VALUE self)
{
rugged_exception_raise();
return Qnil;
}

VALUE rugged__block_yield_splat(VALUE args) {
VALUE block = rb_ary_shift(args);
int n = RARRAY_LENINT(args);
Expand Down Expand Up @@ -451,6 +457,8 @@ void Init_rugged(void)
rb_define_module_function(rb_mRugged, "prettify_message", rb_git_prettify_message, -1);
rb_define_module_function(rb_mRugged, "__cache_usage__", rb_git_cache_usage, 0);

rb_define_private_method(rb_singleton_class(rb_mRugged), "__raise_exception__", rb_git_raise_exception, 0);

Init_rugged_reference();
Init_rugged_reference_collection();

Expand Down
9 changes: 8 additions & 1 deletion test/lib_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ def test_libgit2_version
end
end

def test_raise_exception
# Ensure libgit2 error state is cleared
Rugged.send(:__raise_exception__) rescue nil

err = assert_raises(RuntimeError) { Rugged.send(:__raise_exception__) }
assert_equal "Rugged operation failed", err.message
end

def test_options
Rugged::Settings['mwindow_size'] = 8 * 1024 * 1024
Rugged::Settings['mwindow_mapped_limit'] = 8 * 1024 * 1024
Expand Down Expand Up @@ -141,4 +149,3 @@ def test_prettify_commit_messages
assert_equal clean_message, Rugged::prettify_message(message, true)
end
end

0 comments on commit c937735

Please sign in to comment.