#944 refactoring checking empty project

This commit is contained in:
Alexander Machehin 2013-02-22 13:22:34 +06:00
parent 71de1477b3
commit e08c31e314
2 changed files with 6 additions and 2 deletions

View File

@ -4,7 +4,7 @@ class Projects::Git::TreesController < Projects::Git::BaseController
skip_before_filter :set_branch_and_tree, :set_treeish_and_path, :only => :archive skip_before_filter :set_branch_and_tree, :set_treeish_and_path, :only => :archive
def show def show
render('empty') and return if @project.repo.branches.count == 0 render('empty') and return if @project.empty?
@tree = @tree / @path if @path.present? @tree = @tree / @path if @path.present?
@commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, :max_count => 1).first @commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, :max_count => 1).first
raise Grit::NoSuchPathError unless @commit raise Grit::NoSuchPathError unless @commit
@ -33,7 +33,7 @@ class Projects::Git::TreesController < Projects::Git::BaseController
end end
def branches def branches
raise Grit::NoSuchPathError if !@branch && @project.repo.branches.count != 0 raise Grit::NoSuchPathError if !(@branch && @project.empty?)
@branches = @project.repo.branches.sort_by(&:name).select{ |b| b.name != @branch.name }.unshift(@branch).compact @branches = @project.repo.branches.sort_by(&:name).select{ |b| b.name != @branch.name }.unshift(@branch).compact
render 'refs' render 'refs'
end end

View File

@ -97,6 +97,10 @@ module Modules
system("#{Rails.root.join('bin', 'import_srpm.sh')} #{opts} >> /dev/null 2>&1") system("#{Rails.root.join('bin', 'import_srpm.sh')} #{opts} >> /dev/null 2>&1")
end end
def empty?
repo.branches.count == 0
end
protected protected
def build_path(dir) def build_path(dir)