Skip to content
This repository
Browse code

Make ls_tree ignore nils

  • Loading branch information...
commit 85fea86e27999d2be873656b35b7dc316aa9a2c1 1 parent c0f65cf
Chris Wanstrath authored February 13, 2009
11  lib/grit/git-ruby/repository.rb
@@ -185,16 +185,15 @@ def ls_tree(sha, paths = [])
185 185
       def get_raw_tree(sha)
186 186
         o = get_raw_object_by_sha1(sha)
187 187
         if o.type == :commit
188  
-          tree = cat_file(get_object_by_sha1(sha).tree)
  188
+          cat_file(get_object_by_sha1(sha).tree)
189 189
         elsif o.type == :tag
190 190
           commit_sha = get_object_by_sha1(sha).object
191  
-          tree = cat_file(get_object_by_sha1(commit_sha).tree)
192  
-        else
193  
-          tree = cat_file(sha)
  191
+          cat_file(get_object_by_sha1(commit_sha).tree)
  192
+        elsif o.type == :tree
  193
+          cat_file(sha)
194 194
         end
195  
-        return tree
196 195
       end
197  
-      
  196
+
198 197
       # return array of tree entries
199 198
       ## TODO : refactor this to remove the fugly
200 199
       def ls_tree_path(sha, path, append = nil)
9  test/test_rubygit.rb
@@ -87,17 +87,22 @@ def test_cat_file_size
87 87
     out = @git.cat_file({:s => true}, @tree_sha)
88 88
     assert_equal '252', out
89 89
   end
90  
-  
  90
+
91 91
   def test_ls_tree
92 92
     out = @git.ls_tree({}, @tree_sha)
93 93
     assert_equal out, fixture('cat_file_tree_ruby').chomp
94 94
   end
95 95
 
  96
+  def test_ls_tree_with_blobs
  97
+    out = @git.ls_tree({}, @blob_sha)
  98
+    assert_equal out, nil
  99
+  end
  100
+
96 101
   def test_ls_tree_treeish
97 102
     out = @git.ls_tree({}, 'testing')
98 103
     assert_equal out, fixture('cat_file_tree_ruby').chomp
99 104
   end
100  
-  
  105
+
101 106
   def test_ls_tree_paths
102 107
     paths = ['History.txt', 'lib']
103 108
     out = @git.ls_tree({}, @tree_sha, paths)

0 notes on commit 85fea86

Please sign in to comment.
Something went wrong with that request. Please try again.