public
Fork of mojombo/grit
Description: Grit is a Ruby library for extracting information from a git repository in an object oriented manner.
Homepage: http://grit.rubyforge.org/
Clone URL: git://github.com/technoweenie/grit.git
compact Commit contents from Trees so that #/(path_to_commit) doesn't 
raise a NoMethodError on NilClass#name.
technoweenie (author)
Mon Feb 18 00:55:57 -0800 2008
commit  182a706d083de61af95c3dba0d59dd3f91fe31b2
tree    2bdb7f089a890008730e239f2b894c71ac0d0693
parent  125c3f885f9041a48b2828cd1c707dbaff78a825
...
34
35
36
 
37
38
39
...
34
35
36
37
38
39
40
0
@@ -34,6 +34,7 @@ module Grit
0
       text.split("\n").each do |line|
0
         @contents << content_from_string(repo, line)
0
       end
0
+ @contents.compact!
0
       __baked__
0
       self
0
     end
...
34
35
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
38
39
...
52
53
54
 
 
 
 
 
 
 
 
 
 
 
55
56
57
...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
...
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
0
@@ -34,6 +34,25 @@ class TestTree < Test::Unit::TestCase
0
     assert_equal "test", tree.name
0
   end
0
   
0
+ def test_content_from_string_tree_should_return_blob
0
+ text = fixture('ls_tree_b').split("\n").first
0
+
0
+ tree = @t.content_from_string(nil, text)
0
+
0
+ assert_equal Blob, tree.class
0
+ assert_equal "aa94e396335d2957ca92606f909e53e7beaf3fbb", tree.id
0
+ assert_equal "100644", tree.mode
0
+ assert_equal "grit.rb", tree.name
0
+ end
0
+
0
+ def test_content_from_string_tree_should_return_commit
0
+ text = fixture('ls_tree_commit').split("\n")[1]
0
+
0
+ tree = @t.content_from_string(nil, text)
0
+
0
+ assert_nil tree
0
+ end
0
+
0
   def test_content_from_string_invalid_type_should_raise
0
     assert_raise(RuntimeError) do
0
       @t.content_from_string(nil, "040000 bogus 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44  test")
0
@@ -52,6 +71,17 @@ class TestTree < Test::Unit::TestCase
0
     assert_equal '8b1e02c0fb554eed2ce2ef737a68bb369d7527df', (tree/'README.txt').id
0
   end
0
   
0
+ def test_slash_with_commits
0
+ Git.any_instance.expects(:ls_tree).returns(
0
+ fixture('ls_tree_commit')
0
+ )
0
+ tree = @r.tree('master')
0
+
0
+ assert_nil tree/'bar'
0
+ assert_equal '2afb47bcedf21663580d5e6d2f406f08f3f65f19', (tree/'foo').id
0
+ assert_equal 'f623ee576a09ca491c4a27e48c0dfe04be5f4a2e', (tree/'baz').id
0
+ end
0
+
0
   # inspect
0
   
0
   def test_inspect

Comments

    No one has commented yet.