git_repository.rb revision ef1f1ad3d88023d93475dfdce00bd9f230917660
# Wrapper for access to the local Git repository
#requires git and git-svn to be installed for the functions clone_git and clone_svn to work
include \
if File.exists?(path)
else
end
end
# DELETEME (exists only for debugging purpose)
@repo
end
end
end
if !rugged_commit && url.empty?
true
else
end
end
if !rugged_commit && url.empty?
else
end
end
path ||= ''
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
def self.is_repository_with_working_copy?(path)
repo = Rugged::Repository.new(path)
!repo.bare?
rescue Rugged::RepositoryError
false
end
def self.is_bare_repository?(path)
repo = Rugged::Repository.new(path)
repo.bare?
rescue Rugged::RepositoryError
false
end
protected
def path_exists_rugged?(rugged_commit, url='')
if url.empty? || url == '/'
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