Merge pull request #950 from warpc/944-fix_branch_errors

[refs #944] disable selecting tag on branches page, new way to check empty project and fix undefined method `name' for nil:NilClass
This commit is contained in:
Vladimir Sharshov 2013-02-22 03:24:48 -08:00
commit 96abcad5ce
4 changed files with 14 additions and 7 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
def show
render('empty') and return unless @project.repo.commit nil
render('empty') and return if @project.empty?
@tree = @tree / @path if @path.present?
@commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, :max_count => 1).first
raise Grit::NoSuchPathError unless @commit
@ -33,8 +33,8 @@ class Projects::Git::TreesController < Projects::Git::BaseController
end
def branches
raise Grit::NoSuchPathError if !@branch && @project.repo.commit(nil)
@branches = @project.repo.branches.sort_by(&:name).select{ |b| b.name != @branch.name }.unshift(@branch).compact
raise Grit::NoSuchPathError if params[:treeish] != @branch.try(:name) # get wrong branch name to nonempty project
@branches = @project.repo.branches.sort_by(&:name).select{ |b| b.name != @branch.name }.unshift(@branch).compact if @branch
render 'refs'
end

View File

@ -48,7 +48,7 @@ module GitHelper
end
def branch_selector_options(project)
p = params.dup
p, tag_enabled = params.dup, !(controller_name == 'trees' && action_name == 'branches')
p.delete(:path) if p[:path].present? # to root path
p.merge!(:project_id => project.id, :treeish => project.default_branch).delete(:id) unless p[:treeish].present?
current = url_for(p).split('?', 2).first
@ -59,8 +59,11 @@ module GitHelper
end
linking = Proc.new {|t| [t.name.truncate(20), url_for(p.merge :treeish => t.name).split('?', 2).first]}
res << [I18n.t('layout.git.repositories.branches'), project.repo.branches.map(&linking)]
res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map(&linking)]
if tag_enabled
res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map(&linking)]
else
res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map {|t| [t.name.truncate(20), {:disabled => true}]}]
end
grouped_options_for_select(res, current)
end

View File

@ -1,7 +1,7 @@
- subjects_name = action_name.to_s
%h3= t("layout.projects.#{subjects_name}")
- if subject.empty?
- if subject.blank?
%p= t("layout.projects.no_#{subjects_name}")
- elsif subject.count == 1
%p= t("layout.projects.showing_#{subjects_name.singularize}")

View File

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