Commit a6eff1c1 authored by Luke Duncalfe's avatar Luke Duncalfe

Remove redundant Repository#exists? checks

Removing checks of Repository#exists? before using Repository#root_ref,
as #root_ref returns nil when a repository does not exist.
parent 1fcfac98
......@@ -143,7 +143,7 @@ module SearchHelper
# Autocomplete results for the current project, if it's defined
def project_autocomplete
if @project && @project.repository.exists? && @project.repository.root_ref
if @project && @project.repository.root_ref
ref = @ref || @project.repository.root_ref
[
......
......@@ -1514,7 +1514,7 @@ class Project < ApplicationRecord
end
def default_branch
@default_branch ||= repository.root_ref if repository.exists?
@default_branch ||= repository.root_ref
end
def reload_default_branch
......
......@@ -1331,6 +1331,13 @@ describe Repository do
repository.root_ref
end
it 'returns nil if the repository does not exist' do
repository = create(:project).repository
expect(repository).not_to be_exists
expect(repository.root_ref).to be_nil
end
it_behaves_like 'asymmetric cached method', :root_ref
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment