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
|
2012-09-19 20:29:36 +01:00
|
|
|
before_filter lambda{redirect_to @project if params[:treeish] == @project.default_branch and params[:path].blank?}, :only => :show
|
2013-01-31 17:26:41 +00:00
|
|
|
skip_before_filter :set_branch_and_tree, :set_treeish_and_path, :only => :archive
|
2011-04-04 12:28:33 +01:00
|
|
|
|
2012-07-17 09:02:56 +01:00
|
|
|
def show
|
|
|
|
@tree = @tree / @path if @path.present?
|
|
|
|
@commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, :max_count => 1).first
|
|
|
|
render 'empty' unless @commit
|
2011-03-10 12:39:24 +00:00
|
|
|
end
|
2012-04-17 11:18:03 +01:00
|
|
|
|
|
|
|
def archive
|
2013-01-31 17:26:41 +00:00
|
|
|
format, @treeish = params[:format], params[:treeish]
|
2012-09-20 15:26:26 +01:00
|
|
|
if (@treeish =~ /^#{@project.owner.uname}-#{@project.name}-/) && !(@treeish =~ /[\s]+/) && (format =~ /^(zip|tar\.gz)$/)
|
2012-09-20 12:21:54 +01:00
|
|
|
@treeish = @treeish.gsub(/^#{@project.owner.uname}-#{@project.name}-/, '')
|
|
|
|
@commit = @project.repo.commits(@treeish, 1).first
|
2012-09-19 20:29:36 +01:00
|
|
|
end
|
2012-07-17 09:02:56 +01:00
|
|
|
raise Grit::NoSuchPathError unless @commit
|
2012-09-20 12:21:54 +01:00
|
|
|
name = "#{@project.owner.uname}-#{@project.name}-#{@treeish}"
|
2012-09-20 15:26:26 +01:00
|
|
|
fullname = "#{name}.#{format == 'zip' ? 'zip' : 'tar.gz'}"
|
2012-04-17 11:18:03 +01:00
|
|
|
file = Tempfile.new fullname, 'tmp'
|
2012-10-03 21:27:13 +01:00
|
|
|
system("cd #{@project.path}; git archive --format=#{format == 'zip' ? 'zip' : 'tar'} --prefix=#{name}/ #{@treeish} #{format == 'zip' ? '' : ' | gzip -9'} > #{file.path}")
|
2012-04-17 11:18:03 +01:00
|
|
|
file.close
|
2012-09-20 15:26:26 +01:00
|
|
|
send_file file.path, :disposition => 'attachment', :type => "application/#{format == 'zip' ? 'zip' : 'x-tar-gz'}", :filename => fullname
|
2012-04-17 11:18:03 +01:00
|
|
|
end
|
2012-09-20 12:10:52 +01:00
|
|
|
|
2013-02-12 16:35:14 +00:00
|
|
|
def tags
|
2013-02-13 19:29:08 +00:00
|
|
|
@tags = @project.repo.tags.select{ |t| t.commit }.sort_by(&:name).reverse
|
2013-02-13 17:40:16 +00:00
|
|
|
render 'refs'
|
2013-02-12 16:35:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def branches
|
2013-02-13 11:23:58 +00:00
|
|
|
@branches = @project.repo.branches.sort_by(&:name).select{ |b| b.name != @branch.name }.unshift(@branch)
|
2013-02-13 17:40:16 +00:00
|
|
|
render 'refs'
|
2013-02-12 16:35:14 +00:00
|
|
|
end
|
|
|
|
|
2012-01-30 20:39:34 +00:00
|
|
|
end
|