Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Make ls_tree ignore nils
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Feb 14, 2009
1 parent c0f65cf commit 85fea86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
11 changes: 5 additions & 6 deletions lib/grit/git-ruby/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,15 @@ def ls_tree(sha, paths = [])
def get_raw_tree(sha)
o = get_raw_object_by_sha1(sha)
if o.type == :commit
tree = cat_file(get_object_by_sha1(sha).tree)
cat_file(get_object_by_sha1(sha).tree)
elsif o.type == :tag
commit_sha = get_object_by_sha1(sha).object
tree = cat_file(get_object_by_sha1(commit_sha).tree)
else
tree = cat_file(sha)
cat_file(get_object_by_sha1(commit_sha).tree)
elsif o.type == :tree
cat_file(sha)
end
return tree
end

# return array of tree entries
## TODO : refactor this to remove the fugly
def ls_tree_path(sha, path, append = nil)
Expand Down
9 changes: 7 additions & 2 deletions test/test_rubygit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,22 @@ def test_cat_file_size
out = @git.cat_file({:s => true}, @tree_sha)
assert_equal '252', out
end

def test_ls_tree
out = @git.ls_tree({}, @tree_sha)
assert_equal out, fixture('cat_file_tree_ruby').chomp
end

def test_ls_tree_with_blobs
out = @git.ls_tree({}, @blob_sha)
assert_equal out, nil
end

def test_ls_tree_treeish
out = @git.ls_tree({}, 'testing')
assert_equal out, fixture('cat_file_tree_ruby').chomp
end

def test_ls_tree_paths
paths = ['History.txt', 'lib']
out = @git.ls_tree({}, @tree_sha, paths)
Expand Down

0 comments on commit 85fea86

Please sign in to comment.