Skip to content

Commit 476d943

Browse files
committed
added tree.depth and tree.full_tree
1 parent 099f60d commit 476d943

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

lib/git/lib.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ def ls_tree(sha)
181181

182182
data
183183
end
184+
185+
def full_tree(sha)
186+
command_lines('ls-tree', ['-r', sha.to_s])
187+
end
188+
189+
def tree_depth(sha)
190+
full_tree(sha).size
191+
end
184192

185193
def branches_all
186194
head = File.read(File.join(@git_dir, 'HEAD'))

lib/git/object.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ def trees
124124
alias_method :subtrees, :trees
125125
alias_method :subdirectories, :trees
126126

127+
def full_tree
128+
@base.lib.full_tree(@objectish)
129+
end
130+
131+
def depth
132+
@base.lib.tree_depth(@objectish)
133+
end
134+
127135
private
128136

129137
def setup

tests/units/test_object.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ def test_tree
7272
assert_equal(1, o.blobs.size)
7373
assert_equal(1, o.subtrees.size)
7474
assert_equal(1, o.trees['ex_dir'].blobs.size)
75+
76+
assert_equal(2, o.full_tree.size)
77+
assert_equal("100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\tex_dir/ex.txt", o.full_tree.first)
78+
79+
assert_equal(2, o.depth)
7580

7681
o = @git.gtree('94c827875e2cadb8bc8d4cdd900f19aa9e8634c7')
7782
assert(o.is_a?(Git::Object::Tree))

0 commit comments

Comments
 (0)