Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx> --- ruby.c | 11 +++++++++++ t/t10000-ruby.sh | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/ruby.c b/ruby.c index c2ef72e..0ab56de 100644 --- a/ruby.c +++ b/ruby.c @@ -41,10 +41,21 @@ static VALUE git_rb_for_each_ref(void) return INT2FIX(r); } +static VALUE git_rb_dwim_ref(VALUE self, VALUE name) +{ + unsigned char buf[20]; + char *ref; + int r; + + r = dwim_ref(RSTRING_PTR(name), RSTRING_LEN(name), buf, &ref); + return rb_ary_new3(3, sha1_to_str(buf), INT2NUM(r), cstr_to_str(ref)); +} + static void git_ruby_init(void) { rb_define_global_function("setup_git_directory", git_rb_setup_git_directory, 0); rb_define_global_function("for_each_ref", git_rb_for_each_ref, 0); + rb_define_global_function("dwim_ref", git_rb_dwim_ref, 1); } static int run_ruby_command(const char *cmd, int argc, const char **argv) diff --git a/t/t10000-ruby.sh b/t/t10000-ruby.sh index 2098e29..d719b30 100755 --- a/t/t10000-ruby.sh +++ b/t/t10000-ruby.sh @@ -52,4 +52,15 @@ test_expect_success 'test setup_git_directory()' ' test_cmp expected actual ' +test_expect_success 'test dwim_ref()' ' + git ruby > actual <<-EOF && + sha1, num, ref = dwim_ref("HEAD") + puts sha1_to_hex(sha1), num, ref + EOF + git rev-parse -q --verify HEAD > expected && + echo 1 >> expected && + git rev-parse -q --verify --symbolic-full-name HEAD >> expected && + test_cmp expected actual +' + test_done -- 1.8.4-fc -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html