Method: Technologist::GitRepository#find_blob

Defined in:
lib/technologist/git_repository.rb

#find_blob(blob_name, current_tree = root_tree) ⇒ Rugged::Blob

Recursively searches for the blob identified by ‘blob_name` in all subdirectories in the repository. A blob is usually either a file or a directory.

Parameters:

  • blob_name (String)

    the blob name

  • current_tree (Rugged::Tree) (defaults to: root_tree)

    the git directory tree in which to look for the blob. Defaults to the root tree (see ‘#root_tree`).

Returns:

  • (Rugged::Blob)

    The blob blob or nil if it cannot be found.



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/technologist/git_repository.rb', line 35

def find_blob(blob_name, current_tree = root_tree)
  blob = current_tree[blob_name]

  if blob
    repository.lookup(blob[:oid])
  else
    current_tree.each_tree do |sub_tree|
      blob = find_blob(blob_name, repository.lookup(sub_tree[:oid]))
      break blob if blob
    end
  end
end