2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-05-02 10:18:07 +01:00
|
|
|
class Projects::Git::TreesController < Projects::Git::BaseController
|
2011-03-10 12:39:24 +00:00
|
|
|
def show
|
2012-03-21 19:55:14 +00:00
|
|
|
redirect_to project_path(@project) and return if params[:treeish] == @project.default_branch and params[:path].blank?
|
2012-02-21 15:41:16 +00:00
|
|
|
|
2011-03-10 12:39:24 +00:00
|
|
|
@path = params[:path]
|
2011-03-11 17:19:47 +00:00
|
|
|
@tree = @git_repository.tree(@treeish)
|
2012-02-21 15:41:16 +00:00
|
|
|
@branch = @project.branch(@treeish)
|
2011-04-04 12:28:33 +01:00
|
|
|
|
2011-04-07 14:20:21 +01:00
|
|
|
# @commit = @git_repository.commits(@treeish, 1).first
|
2011-04-04 14:49:08 +01:00
|
|
|
# Raises Grit::Git::GitTimeout
|
2012-02-21 15:41:16 +00:00
|
|
|
@commit = @branch.present? ? @branch.commit() : @git_repository.log(@treeish, @path, :max_count => 1).first
|
2012-05-02 10:18:07 +01:00
|
|
|
render "empty" and return unless @commit
|
2011-03-10 12:39:24 +00:00
|
|
|
|
2012-03-21 19:55:14 +00:00
|
|
|
@tree = @tree / @path if @path
|
2011-03-10 12:39:24 +00:00
|
|
|
end
|
2012-04-17 11:18:03 +01:00
|
|
|
|
|
|
|
def archive
|
|
|
|
treeish = params[:treeish].presence || @project.default_branch
|
|
|
|
format = params[:format] || 'tar'
|
|
|
|
commit = @project.git_repository.log(treeish, nil, :max_count => 1).first
|
2012-04-24 19:03:30 +01:00
|
|
|
if !commit or !['tar', 'zip'].include?(format)
|
|
|
|
raise ActiveRecord::RecordNotFound#("Couldn't send Project archive with id=#{@project.id}, treeish=#{treeish} and format=#{format}")
|
|
|
|
end
|
2012-04-17 11:18:03 +01:00
|
|
|
name = "#{@project.owner.uname}-#{@project.name}#{@project.tags.include?(treeish) ? "-#{treeish}" : ''}-#{commit.id[0..19]}"
|
|
|
|
fullname = "#{name}.#{format == 'tar' ? 'tar.gz' : 'zip'}"
|
|
|
|
file = Tempfile.new fullname, 'tmp'
|
|
|
|
system("cd #{@project.path}; git archive --format=#{format} --prefix=#{name}/ #{treeish} #{format == 'tar' ? ' | gzip -9' : ''} > #{file.path}")
|
|
|
|
file.close
|
2012-05-02 10:18:07 +01:00
|
|
|
send_file file.path, :disposition => 'attachment', :type => "application/#{format == 'tar' ? 'x-tar-gz' : 'zip'}", :filename => fullname
|
2012-04-17 11:18:03 +01:00
|
|
|
end
|
2012-01-30 20:39:34 +00:00
|
|
|
end
|