Skip to content

Commit

Permalink
Merge pull request #401 from libgit2/type-check-read-tree
Browse files Browse the repository at this point in the history
Type check the tree value for Rugged::Index#read_tree
  • Loading branch information
arthurschreiber committed Aug 22, 2014
2 parents 3d8c4c2 + 7339250 commit ab675f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/rugged/rugged_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ static VALUE rb_git_index_readtree(VALUE self, VALUE rb_tree)
Data_Get_Struct(self, git_index, index);
Data_Get_Struct(rb_tree, git_tree, tree);

if (!rb_obj_is_kind_of(rb_tree, rb_cRuggedTree)) {
rb_raise(rb_eTypeError, "A Rugged::Tree instance is required");
}

error = git_index_read_tree(index, tree);
rugged_exception_check(error);

Expand Down
10 changes: 10 additions & 0 deletions test/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ def test_build_tree_from_index
assert head_sha != new_tree_sha
assert_nil @repo.lookup(new_tree_sha)['second.txt']
end

def test_read_tree_with_not_a_tree
head_sha = @repo.references['refs/remotes/origin/packed'].resolve.target_id
commit = @repo.lookup(head_sha)

index = @repo.index
assert_raises TypeError do
index.read_tree(commit)
end
end
end

class IndexAddAllTest < Rugged::SandboxedTestCase
Expand Down

0 comments on commit ab675f8

Please sign in to comment.