Ensure default_branch from settings is not blank

parent f0afb27e
......@@ -88,7 +88,7 @@ module HasRepository
group_branch_default_name = group&.default_branch_name if respond_to?(:group)
group_branch_default_name || Gitlab::CurrentSettings.default_branch_name
(group_branch_default_name || Gitlab::CurrentSettings.default_branch_name).presence
end
def reload_default_branch
......
---
title: Ensure default_branch from settings is not blank
merge_request: 49018
author:
type: fixed
......@@ -5071,11 +5071,11 @@ RSpec.describe Project, factory_default: :keep do
end
end
describe "#default_branch" do
context "with an empty repository" do
describe '#default_branch' do
context 'with an empty repository' do
let_it_be(:project) { create(:project_empty_repo) }
context "group.default_branch_name is available" do
context 'group.default_branch_name is available' do
let(:project_group) { create(:group) }
let(:project) { create(:project, path: 'avatar', namespace: project_group) }
......@@ -5088,19 +5088,19 @@ RSpec.describe Project, factory_default: :keep do
.and_return('example_branch')
end
it "returns the group default value" do
expect(project.default_branch).to eq("example_branch")
it 'returns the group default value' do
expect(project.default_branch).to eq('example_branch')
end
end
context "Gitlab::CurrentSettings.default_branch_name is available" do
context 'Gitlab::CurrentSettings.default_branch_name is available' do
before do
expect(Gitlab::CurrentSettings)
.to receive(:default_branch_name)
.and_return(example_branch_name)
end
context "is missing or nil" do
context 'is missing or nil' do
let(:example_branch_name) { nil }
it "returns nil" do
......@@ -5108,10 +5108,18 @@ RSpec.describe Project, factory_default: :keep do
end
end
context "is present" do
let(:example_branch_name) { "example_branch_name" }
context 'is blank' do
let(:example_branch_name) { '' }
it "returns the expected branch name" do
it 'returns nil' do
expect(project.default_branch).to be_nil
end
end
context 'is present' do
let(:example_branch_name) { 'example_branch_name' }
it 'returns the expected branch name' do
expect(project.default_branch).to eq(example_branch_name)
end
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