Class: Git::Object::Tree

Inherits:
AbstractObject show all
Defined in:
lib/git/object.rb

Overview

A Git tree object

Instance Attribute Summary

Attributes inherited from AbstractObject

#mode, #objectish, #size, #type

Instance Method Summary collapse

Methods inherited from AbstractObject

#archive, #blob?, #commit?, #contents, #contents_array, #diff, #grep, #log, #sha, #tag?, #to_s

Constructor Details

#initialize(base, sha, mode = nil) ⇒ Tree

Creates a tree object wrapper

Parameters:

  • base (Git::Repository)

    the repository used to query object data

  • sha (String)

    the tree SHA or object expression

  • mode (String, nil) (defaults to: nil)

    the file mode from tree listings



299
300
301
302
303
304
# File 'lib/git/object.rb', line 299

def initialize(base, sha, mode = nil)
  super(base, sha)
  @mode = mode
  @trees = nil
  @blobs = nil
end

Instance Method Details

#blobsHash<String, Git::Object::Blob> Also known as: files

Returns blobs directly under this tree

Returns:



318
319
320
# File 'lib/git/object.rb', line 318

def blobs
  @blobs ||= check_tree[:blobs]
end

#childrenHash<String, Git::Object::AbstractObject>

Returns child blobs and subtrees keyed by name

Returns:



310
311
312
# File 'lib/git/object.rb', line 310

def children
  blobs.merge(subtrees)
end

#depthInteger

Returns the maximum depth of this tree

Returns:

  • (Integer)

    maximum tree depth



345
346
347
# File 'lib/git/object.rb', line 345

def depth
  object_repository.tree_depth(@objectish)
end

#full_treeHash

Returns the full tree listing for this tree

Returns:

  • (Hash)

    parsed recursive tree data



337
338
339
# File 'lib/git/object.rb', line 337

def full_tree
  object_repository.full_tree(@objectish)
end

#tree?Boolean

Returns whether this object is a tree

Returns:

  • (Boolean)

    true



353
354
355
# File 'lib/git/object.rb', line 353

def tree?
  true
end

#treesHash<String, Git::Object::Tree> Also known as: subtrees, subdirectories

Returns subtrees directly under this tree

Returns:



327
328
329
# File 'lib/git/object.rb', line 327

def trees
  @trees ||= check_tree[:trees]
end