Project.repository should never be nil so you can call repository.exists? or repository.empty?

Also specify separate project factory for project with filled repo
This commit is contained in:
Dmitriy Zaporozhets 2013-04-01 16:56:25 +03:00
parent 49b024f5f5
commit 541d899410
13 changed files with 51 additions and 54 deletions

View file

@ -96,7 +96,7 @@ module ApplicationHelper
]
project_nav = []
if @project && @project.repository && @project.repository.root_ref
if @project && @project.repository.exists? && @project.repository.root_ref
project_nav = [
{ label: "#{simple_sanitize(@project.name_with_namespace)} - Issues", url: project_issues_path(@project) },
{ label: "#{simple_sanitize(@project.name_with_namespace)} - Commits", url: project_commits_path(@project, @ref || @project.repository.root_ref) },

View file

@ -141,13 +141,7 @@ class Project < ActiveRecord::Base
end
def repository
if path
@repository ||= Repository.new(path_with_namespace, default_branch)
else
nil
end
rescue Gitlab::Git::NoRepository
nil
@repository ||= Repository.new(path_with_namespace, default_branch)
end
def saved?
@ -332,14 +326,14 @@ class Project < ActiveRecord::Base
end
def valid_repo?
repo
repository.exists?
rescue
errors.add(:path, "Invalid repository path")
false
end
def empty_repo?
!repository || repository.empty?
!repository.exists? || repository.empty?
end
def ensure_satellite_exists
@ -363,7 +357,7 @@ class Project < ActiveRecord::Base
end
def repo_exists?
@repo_exists ||= (repository && repository.branches.present?)
@repo_exists ||= repository.exists?
rescue
@repo_exists = false
end

View file

@ -3,6 +3,16 @@ class Repository
def initialize(path_with_namespace, default_branch)
@raw_repository = Gitlab::Git::Repository.new(path_with_namespace, default_branch)
rescue Gitlab::Git::Repository::NoRepository
nil
end
def exists?
raw_repository
end
def empty?
raw_repository.empty?
end
def commit(id = nil)

View file

@ -4,7 +4,7 @@
.form-horizontal= render "shared/clone_panel"
.span4.pull-right
.pull-right
- unless @project.empty_repo?
- if @project.empty_repo?
- if can? current_user, :download_code, @project
= link_to archive_project_repository_path(@project), class: "btn-small btn grouped" do
%i.icon-download-alt