Skip to content

Commit

Permalink
add head method to repo and resolve method to references
Browse files Browse the repository at this point in the history
includes associated unit tests
  • Loading branch information
tclem authored and vmg committed Mar 14, 2011
1 parent 7a48215 commit 658c903
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions ext/rugged/rugged_reference.c
Expand Up @@ -221,5 +221,6 @@ void Init_rugged_reference()
rb_define_method(rb_cRuggedReference, "name", rb_git_ref_name, 0);
rb_define_method(rb_cRuggedReference, "name=", rb_git_ref_rename, 1);

rb_define_method(rb_cRuggedReference, "resolve", rb_git_ref_resolve, 0);
rb_define_method(rb_cRuggedReference, "delete", rb_git_ref_delete, 0);
}
5 changes: 5 additions & 0 deletions lib/rugged/repository.rb
Expand Up @@ -10,6 +10,11 @@ def walk(from, sorting=Rugged::SORT_DATE)
yield commit
end
end

def head
ref = Reference.lookup(self, "HEAD")
ref.resolve
end
end

end
11 changes: 11 additions & 0 deletions test/reference_test.rb
Expand Up @@ -50,4 +50,15 @@
assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", ref.target
ref.delete
end

test "can resolve head" do
ref = Rugged::Reference.lookup(@repo, "HEAD")
assert_equal "refs/heads/master", ref.target
assert_equal "tree", ref.type

head = ref.resolve
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", head.target
assert_equal "commit", head.type
end

end
6 changes: 6 additions & 0 deletions test/repo_test.rb
Expand Up @@ -71,6 +71,12 @@
assert list.map {|c| c.sha[0,5] }.join('.'), "a4a7d.c4780.9fd73.4a202.5b5b0.84960"
end

test "can lookup head from repo" do
head = @repo.head
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", head.target
assert_equal "commit", head.type
end

test "garbage collection methods don't crash" do
Rugged::Repository.new(@path)
ObjectSpace.garbage_collect
Expand Down

0 comments on commit 658c903

Please sign in to comment.