Permalink
Browse files

Make pure-ruby `ls-tree -r` work with commits

  • Loading branch information...
1 parent 01f015d commit 1937a1e49217fc171aa3756424de328e4bd715d7 @defunkt defunkt committed Feb 10, 2010
Showing with 18 additions and 7 deletions.
  1. +7 −5 lib/grit/git-ruby/repository.rb
  2. +1 −1 test/fixtures/ls_tree_recursive
  3. +10 −1 test/test_rubygit.rb
@@ -186,15 +186,17 @@ def ls_tree(sha, paths = [], recursive = false)
def get_raw_tree(sha, recursive = false)
o = get_raw_object_by_sha1(sha)
if o.type == :commit
- cat_file(get_object_by_sha1(sha).tree)
+ tree = get_object_by_sha1(sha).tree
elsif o.type == :tag
commit_sha = get_object_by_sha1(sha).object
- cat_file(get_object_by_sha1(commit_sha).tree)
- elsif o.type == :tree && recursive
- get_raw_trees(sha)
+ tree = get_object_by_sha1(commit_sha).tree
elsif o.type == :tree
- cat_file(sha)
+ tree = sha
+ else
+ return nil
end
+
+ recursive ? get_raw_trees(tree) : cat_file(tree)
end
# Grabs tree contents recursively,
@@ -10,7 +10,7 @@
100644 blob 4dd88a9f7f33730514cd84fd519dcb42644676b7 lib/grit/config.rb
100644 blob a572e57783475b70d8e71abbbe55b74c6fecfdfa lib/grit/diff.rb
100644 blob 61742a7573852a41cfa1e30e0d05ecd58139eab8 lib/grit/errors.rb
-100644 blob ad42ff593e936be1ec7ac17346beab0a0761e278 lib/grit/git.rb
+100644 blob aa50f09c8d855e75effed0ea480f407ab6a2b2b2 lib/grit/git.rb
100644 blob 6865bf036695bed006fdfb2a8abd8a6b83fb149e lib/grit/head.rb
100644 blob 15494f9e1bb59ddafe38d9229a3099d1c40f6919 lib/grit/lazy.rb
100644 blob 2708835b0ec94d20c13159b0839e2c915231437b lib/grit/repo.rb
View
@@ -120,7 +120,16 @@ def test_ls_tree_paths_multi_single
end
def test_ls_tree_recursive
- out = @git.ls_tree({:r => true}, @tree_sha)
+ # this is the tree associated with @commit_sha, which we use in
+ # the next test
+ tree_sha = '77fc9894c0904279fde93adc9c0ba231515ce68a'
+
+ out = @git.ls_tree({:r => true}, tree_sha)
+ assert_equal out, fixture('ls_tree_recursive')
+ end
+
+ def test_ls_tree_recursive_with_a_commit
+ out = @git.ls_tree({:r => true}, @commit_sha)
assert_equal out, fixture('ls_tree_recursive')
end

0 comments on commit 1937a1e

Please sign in to comment.