Commit c8abb527 authored by Tiago Botelho's avatar Tiago Botelho

Empty repository mirror no longer creates master branch with README automatically

parent ceb63966
class CreateBranchService < BaseService class CreateBranchService < BaseService
def execute(branch_name, ref) def execute(branch_name, ref, create_master_if_empty: true)
create_master_branch if project.empty_repo? create_master_branch if create_master_if_empty && project.empty_repo?
result = ValidateNewBranchService.new(project, current_user) result = ValidateNewBranchService.new(project, current_user)
.execute(branch_name) .execute(branch_name)
......
...@@ -36,7 +36,7 @@ module Projects ...@@ -36,7 +36,7 @@ module Projects
local_branch = local_branches[name] local_branch = local_branches[name]
if local_branch.nil? 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 if result[:status] == :error
errors << result[:message] errors << result[:message]
end 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 ...@@ -63,6 +63,31 @@ describe Projects::UpdateMirrorService do
expect(project.repository.find_branch('markdown').dereferenced_target) expect(project.repository.find_branch('markdown').dereferenced_target)
.not_to eq(project.repository.find_branch('master').dereferenced_target) .not_to eq(project.repository.find_branch('master').dereferenced_target)
end 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 end
describe "when the mirror user doesn't have access" do 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