From e08c31e31433447d7d65d1a4d5902d65b8017d0b Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 22 Feb 2013 13:22:34 +0600 Subject: [PATCH] #944 refactoring checking empty project --- app/controllers/projects/git/trees_controller.rb | 4 ++-- lib/modules/models/git.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/git/trees_controller.rb b/app/controllers/projects/git/trees_controller.rb index 68c264681..a9e7ba396 100644 --- a/app/controllers/projects/git/trees_controller.rb +++ b/app/controllers/projects/git/trees_controller.rb @@ -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 if @project.repo.branches.count == 0 + 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,7 +33,7 @@ class Projects::Git::TreesController < Projects::Git::BaseController end 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 render 'refs' end diff --git a/lib/modules/models/git.rb b/lib/modules/models/git.rb index a8269209a..04b7dc6d6 100644 --- a/lib/modules/models/git.rb +++ b/lib/modules/models/git.rb @@ -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)