2011-11-20 20:32:12 +00:00
|
|
|
class Tree
|
2013-10-01 14:00:28 +00:00
|
|
|
attr_accessor :entries, :readme
|
2011-11-20 20:32:12 +00:00
|
|
|
|
2013-10-01 14:00:28 +00:00
|
|
|
def initialize(repository, sha, path = '/')
|
|
|
|
path = '/' if path.blank?
|
|
|
|
git_repo = repository.raw_repository
|
|
|
|
@entries = Gitlab::Git::Tree.where(git_repo, sha, path)
|
|
|
|
|
|
|
|
if readme_tree = @entries.find(&:readme?)
|
2013-10-13 13:03:16 +00:00
|
|
|
readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name)
|
|
|
|
@readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path)
|
2013-10-01 14:00:28 +00:00
|
|
|
end
|
2011-11-20 20:32:12 +00:00
|
|
|
end
|
2011-11-22 12:50:47 +00:00
|
|
|
|
2013-10-01 14:00:28 +00:00
|
|
|
def trees
|
|
|
|
@entries.select(&:dir?)
|
2011-11-22 12:50:47 +00:00
|
|
|
end
|
2013-03-31 20:48:12 +00:00
|
|
|
|
2013-10-01 14:00:28 +00:00
|
|
|
def blobs
|
|
|
|
@entries.select(&:file?)
|
|
|
|
end
|
2013-03-31 20:48:12 +00:00
|
|
|
|
2013-10-01 14:00:28 +00:00
|
|
|
def submodules
|
|
|
|
@entries.select(&:submodule?)
|
2013-03-31 20:48:12 +00:00
|
|
|
end
|
2014-02-04 12:46:15 +00:00
|
|
|
|
|
|
|
def sorted_entries
|
|
|
|
trees + blobs + submodules
|
|
|
|
end
|
2011-11-20 20:32:12 +00:00
|
|
|
end
|