Ensure default_branch from settings is not blank

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