rosa-build/app/controllers/projects/git/trees_controller.rb

51 lines
2.0 KiB
Ruby
Raw Normal View History

2012-01-30 20:39:34 +00:00
# -*- encoding : utf-8 -*-
class Projects::Git::TreesController < Projects::Git::BaseController
before_filter lambda{redirect_to @project if params[:treeish] == @project.default_branch and params[:path].blank?}, :only => :show
skip_before_filter :set_branch_and_tree, :set_treeish_and_path, :only => :archive
2013-07-11 14:03:02 +01:00
before_filter lambda { raise Grit::NoSuchPathError if params[:treeish] != @branch.try(:name) }, :only => [:branch, :destroy]
skip_authorize_resource :project, :only => [:destroy, :restore_branch]
before_filter lambda { authorize!(:write, @project) }, :only => [:destroy, :restore_branch]
def show
render('empty') and return if @project.is_empty?
@tree = @tree / @path if @path.present?
@commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, :max_count => 1).first
2013-02-21 19:23:45 +00:00
raise Grit::NoSuchPathError unless @commit
end
def archive
format, @treeish = params[:format], params[:treeish]
if (@treeish =~ /^#{@project.name}-/) && !(@treeish =~ /[\s]+/) && (format =~ /^(zip|tar\.gz)$/)
@treeish = @treeish.gsub(/^#{@project.name}-/, '')
2012-09-20 12:21:54 +01:00
@commit = @project.repo.commits(@treeish, 1).first
end
raise Grit::NoSuchPathError unless @commit
tag = @project.repo.tags.find{ |t| t.name == @treeish }
sha1 = @project.get_project_tag_sha1(tag, format) if tag
if sha1
redirect_to "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha1}"
else
archive = @project.archive_by_treeish_and_format @treeish, format
send_file archive[:path], :disposition => 'attachment', :type => "application/#{format == 'zip' ? 'zip' : 'x-tar-gz'}", :filename => archive[:fullname]
end
end
2013-02-12 16:35:14 +00:00
def tags
end
2013-07-12 15:21:46 +01:00
def restore_branch
@project.restore_branch @treeish, params[:sha] if @treeish.present? && params[:sha].present?
2013-07-12 15:21:46 +01:00
render :nothing => true
end
def destroy
status = @branch && @project.delete_branch(@branch, current_user) ? 200 : 422
render :nothing => true, :status => status
end
2013-02-12 16:35:14 +00:00
def branches
end
2012-01-30 20:39:34 +00:00
end