#385: fixed specs, updated controller, view

This commit is contained in:
Vokhmin Alexey V 2012-09-19 23:29:36 +04:00
parent c77fc28b21
commit f39adfd2f7
4 changed files with 23 additions and 10 deletions

View File

@ -10,7 +10,11 @@ class Projects::Git::BaseController < Projects::BaseController
protected
def set_treeish_and_path
@treeish = params[:treeish].presence || @project.default_branch
@treeish = params[:treeish].presence
unless @treeish
commit = @project.repo.commits(@project.default_branch).first
@treeish = commit ? commit.id : @project.default_branch
end
@path = params[:path]
end

View File

@ -1,6 +1,8 @@
# -*- 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'
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, :only => :archive
def show
@tree = @tree / @path if @path.present?
@ -9,13 +11,17 @@ class Projects::Git::TreesController < Projects::Git::BaseController
end
def archive
@commit = @project.repo.log(@treeish, nil, :max_count => 1).first
format = params[:format]
if (@treeish =~ /^#{@project.owner.uname}-#{@project.name}-/) && !(@treeish =~ /[\s]+/) && (format =~ /^[\w]+$/)
@treeish = @treeish.gsub(/^#{@project.owner.uname}-#{@project.name}-/, '')
@commit = @project.repo.log(@treeish, nil, :max_count => 1).first
end
raise Grit::NoSuchPathError unless @commit
name = "#{@project.owner.uname}-#{@project.name}#{@project.repo.tags.include?(@treeish) ? "-#{@treeish}" : ''}-#{@commit.id[0..19]}"
fullname = "#{name}.#{params[:format] == 'tar' ? 'tar.gz' : 'zip'}"
name = "#{@project.owner.uname}-#{@project.name}-#{@treeish}"
fullname = "#{name}.#{format == 'tar' ? 'tar.gz' : 'zip'}"
file = Tempfile.new fullname, 'tmp'
system("cd #{@project.path}; git archive --format=#{params[:format]} --prefix=#{name}/ #{@treeish} #{params[:format] == 'tar' ? ' | gzip -9' : ''} > #{file.path}")
system("cd #{@project.path}; git archive --format=#{format} --prefix=#{name}/ #{@treeish} #{format == 'tar' ? ' | gzip -9' : ''} > #{file.path}")
file.close
send_file file.path, :disposition => 'attachment', :type => "application/#{params[:format] == 'tar' ? 'x-tar-gz' : 'zip'}", :filename => fullname
send_file file.path, :disposition => 'attachment', :type => "application/#{format == 'tar' ? 'x-tar-gz' : 'zip'}", :filename => fullname
end
end

View File

@ -6,8 +6,9 @@
=image_tag 'zip.png', :alt => 'ZIP'
%b.caret
%ul.dropdown-menu
%li=link_to "tar.gz", archive_path(project, @treeish, 'tar')
%li=link_to "zip", archive_path(project, @treeish, 'zip')
- file_name = "#{@project.owner.uname}-#{@project.name}-#{@treeish}"
%li=link_to "tar.gz", archive_path(project, file_name, 'tar')
%li=link_to "zip", archive_path(project, file_name, 'zip')
= text_field_tag :url, git_repo_url(project.git_repo_name), :class => 'name', :spellcheck => 'false', :readonly => true
.git_help ?

View File

@ -12,7 +12,9 @@ describe Projects::Git::TreesController do
@project = FactoryGirl.create(:project)
@another_user = FactoryGirl.create(:user)
@params = {:owner_name => @project.owner.uname, :project_name => @project.name, :treeish => 'master'}
@params = { :owner_name => @project.owner.uname,
:project_name => @project.name,
:treeish => "#{@project.owner.uname}-#{@project.name}-master"}
end
context 'for guest' do