Commit 39fa7478 authored by Douwe Maan's avatar Douwe Maan

Merge branch '2425-fix-failure-for-mirrors-with-empty-repository' into 'master'

Empty repository mirror no longer creates master branch with README automatically

Closes #2425

See merge request !2276
parents e9cb4e3a c8abb527
class CreateBranchService < BaseService
def execute(branch_name, ref)
create_master_branch if project.empty_repo?
def execute(branch_name, ref, create_master_if_empty: true)
create_master_branch if create_master_if_empty && project.empty_repo?
result = ValidateNewBranchService.new(project, current_user)
.execute(branch_name)
......
......@@ -36,7 +36,7 @@ module Projects
local_branch = local_branches[name]
if local_branch.nil?
result = CreateBranchService.new(project, current_user).execute(name, upstream_branch.dereferenced_target.sha)
result = CreateBranchService.new(project, current_user).execute(name, upstream_branch.dereferenced_target.sha, create_master_if_empty: false)
if result[:status] == :error
errors << result[:message]
end
......
---
title: Empty repository mirror no longer creates master branch with README automatically.
merge_request: 2276
author:
......@@ -63,6 +63,31 @@ describe Projects::UpdateMirrorService do
expect(project.repository.find_branch('markdown').dereferenced_target)
.not_to eq(project.repository.find_branch('master').dereferenced_target)
end
describe 'when project is empty' do
let(:project) { create(:project_empty_repo, :mirror, import_url: Project::UNKNOWN_IMPORT_URL) }
it 'does not add a default master branch' do
repository = project.repository
allow(project).to receive(:fetch_mirror) { create_file(repository) }
expect(CreateBranchService).not_to receive(:create_master_branch)
described_class.new(project, project.owner).execute
expect(repository.branch_names).not_to include('master')
end
end
def create_file(repository)
repository.create_file(
project.owner,
'/newfile.txt',
'hello',
message: 'Add newfile.txt',
branch_name: 'newbranch'
)
end
end
describe "when the mirror user doesn't have access" do
......
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