Commit 3326fc75 authored by Kerri Miller's avatar Kerri Miller

Add default_branch_name as fallback when available

parent 6566448f
......@@ -76,7 +76,7 @@ module HasRepository
end
def default_branch
@default_branch ||= repository.root_ref
@default_branch ||= repository.root_ref || Gitlab::CurrentSettings.default_branch_name
end
def reload_default_branch
......
......@@ -67,6 +67,7 @@ RSpec.describe 'Projects > Show > User sees Git instructions' do
before do
expect(Gitlab::CurrentSettings)
.to receive(:default_branch_name)
.at_least(:once)
.and_return('example_branch')
sign_in(project.owner)
......
......@@ -4861,6 +4861,36 @@ RSpec.describe Project do
end
end
describe "#default_branch" do
context "with an empty repository" do
let_it_be(:project) { create(:project_empty_repo) }
context "Gitlab::CurrentSettings.default_branch_name is unavailable" do
before do
expect(Gitlab::CurrentSettings)
.to receive(:default_branch_name)
.and_return(nil)
end
it "returns that value" do
expect(project.default_branch).to be_nil
end
end
context "Gitlab::CurrentSettings.default_branch_name is available" do
before do
expect(Gitlab::CurrentSettings)
.to receive(:default_branch_name)
.and_return('example_branch')
end
it "returns that value" do
expect(project.default_branch).to eq("example_branch")
end
end
end
end
describe '#to_ability_name' do
it 'returns project' do
project = build(:project_empty_repo)
......
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