Commit 02e4d7fe authored by Stan Hu's avatar Stan Hu

Defer updating .git/config for imported projects

Normally when a project is created, `Projects::CreateService` attempts
to initialize a Git directory and update the `.git/config` to include
the human-readable project full path.  However, for forks and project
imports, the repository is imported in a separate background job
(e.g. RepositoryForkWorker, RepositoryImportWorker). As a result,
attempts to write to the `.git/config` directory will fail unless the
job has completed first.

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/35305 will ensure
that the `.git/config` is updated after the import is successful. This
commit will prevent attempts to `.git/config` for project imports and
forks from occuring right after project creation.
parent 5e090e9c
......@@ -84,8 +84,12 @@ module Projects
def after_create_actions
log_info("#{@project.owner.name} created a new project \"#{@project.full_name}\"")
# Skip writing the config for project imports/forks because it
# will always fail since the Git directory doesn't exist until
# a background job creates it (see Project#add_import_job).
@project.write_repository_config unless @project.import?
unless @project.gitlab_project_import?
@project.write_repository_config
@project.create_wiki unless skip_wiki?
end
......
---
title: Defer updating .git/config for imported projects
merge_request: 35308
author:
type: fixed
......@@ -240,13 +240,21 @@ RSpec.describe Projects::CreateService, '#execute' do
end
context 'import data' do
it 'stores import data and URL' do
import_data = { data: { 'test' => 'some data' } }
project = create_project(user, { name: 'test', import_url: 'http://import-url', import_data: import_data })
let(:import_data) { { data: { 'test' => 'some data' } } }
let(:imported_project) { create_project(user, { name: 'test', import_url: 'http://import-url', import_data: import_data }) }
it 'does not write repository config' do
expect_next_instance_of(Project) do |project|
expect(project).not_to receive(:write_repository_config)
end
expect(project.import_data).to be_persisted
expect(project.import_data.data).to eq(import_data[:data])
expect(project.import_url).to eq('http://import-url')
imported_project
end
it 'stores import data and URL' do
expect(imported_project.import_data).to be_persisted
expect(imported_project.import_data.data).to eq(import_data[:data])
expect(imported_project.import_url).to eq('http://import-url')
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