git_repository.rb revision a5a4e2f7ee10435dab96569b4514486f0eee6c09
# Wrapper for access to the local Git repository
include \
if File.exists?(path)
else
end
end
end
end
if !rugged_commit && url.empty?
true
else
end
end
if !rugged_commit && url.empty?
else
end
end
url ||= ''
end
end
@repo.refs.map do |r|
{
}
end
end
if ref.nil?
else
end
end
file_path << file_name
file_path
end
def is_head?(commit_oid=nil)
commit_oid == nil || (!@repo.empty? && commit_oid == head_oid)
end
def head_oid
@repo.head.target
end
protected
def path_exists_rugged?(rugged_commit, url='')
if url.empty?
true
else
tree = rugged_commit.tree
nil != get_object(rugged_commit, url)
end
rescue Rugged::OdbError
false
end
def get_file_rugged(rugged_commit, url='')
return nil unless path_exists_rugged?(rugged_commit, url)
object = get_object(rugged_commit, url)
if object.type == :blob
filename = url.split('/')[-1]
mime_info = mime_info(filename)
{
name: filename,
size: object.size,
content: object.content,
mime_type: mime_info[:mime_type],
mime_category: mime_info[:mime_category]
}
else
nil
end
end
def mime_info(filename)
ext = File.extname(filename)[1..-1]
mime_type = Mime::Type.lookup_by_extension(ext) || Mime::TEXT
mime_category = mime_type.to_s.split('/')[0]
{
mime_type: mime_type,
mime_category: mime_category
}
end
def head
@repo.lookup(head_oid)
end
end