Handle raw_repository returning nil in exists?

If path_with_namespace is nil Repository#raw_repository will also return
nil. Apparently code out there creates a Repository instance without a
namespace path. Right.
This commit is contained in:
Yorick Peterse 2016-02-18 14:19:35 +01:00
parent 19b21c2e0c
commit 5b6d347fcd
2 changed files with 8 additions and 0 deletions

View File

@ -38,6 +38,8 @@ class Repository
end
def exists?
return false unless raw_repository
raw_repository.rugged
true
rescue Gitlab::Git::Repository::NoRepository

View File

@ -240,6 +240,12 @@ describe Repository, models: true do
expect(repository.exists?).to eq(false)
end
it 'returns false when there is no namespace' do
allow(repository).to receive(:path_with_namespace).and_return(nil)
expect(repository.exists?).to eq(false)
end
end
describe '#has_visible_content?' do