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:
parent
49b024f5f5
commit
541d899410
13 changed files with 51 additions and 54 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue