Commit bbf35765 authored by Pavel Shutsin's avatar Pavel Shutsin

Allow to fork to the same namespace with different name

API allows to set alternative name and path for forks,
so same namespace as source project can be valid fork target
parent 152c312d
......@@ -39,7 +39,7 @@ class Projects::ForksController < Projects::ApplicationController
# rubocop: enable CodeReuse/ActiveRecord
def new
@namespaces = fork_service.valid_fork_targets
@namespaces = fork_service.valid_fork_targets - [project.namespace]
end
# rubocop: disable CodeReuse/ActiveRecord
......
......@@ -8,7 +8,7 @@ class ForkTargetsFinder
# rubocop: disable CodeReuse/ActiveRecord
def execute
::Namespace.where(id: user.manageable_namespaces).where.not(id: project.namespace).sort_by_type
::Namespace.where(id: user.manageable_namespaces).sort_by_type
end
# rubocop: enable CodeReuse/ActiveRecord
......
---
title: Allow to fork to the same namespace and different path via API call
merge_request: 26062
author:
type: fixed
......@@ -28,8 +28,8 @@ describe ForkTargetsFinder do
end
describe '#execute' do
it 'returns all user manageable namespaces except project namespace' do
expect(finder.execute).to match_array([user.namespace, maintained_group, owned_group])
it 'returns all user manageable namespaces' do
expect(finder.execute).to match_array([user.namespace, maintained_group, owned_group, project.namespace])
end
end
end
......@@ -2935,6 +2935,26 @@ describe API::Projects do
expect(response).to have_gitlab_http_status(:conflict)
expect(json_response['message']['name']).to eq(['has already been taken'])
end
it 'forks to the same namespace with alternative path and name' do
post api("/projects/#{project.id}/fork", user), params: { path: 'path_2', name: 'name_2' }
expect(response).to have_gitlab_http_status(:created)
expect(json_response['name']).to eq('name_2')
expect(json_response['path']).to eq('path_2')
expect(json_response['owner']['id']).to eq(user.id)
expect(json_response['namespace']['id']).to eq(user.namespace.id)
expect(json_response['forked_from_project']['id']).to eq(project.id)
expect(json_response['import_status']).to eq('scheduled')
end
it 'fails to fork to the same namespace without alternative path and name' do
post api("/projects/#{project.id}/fork", user)
expect(response).to have_gitlab_http_status(:conflict)
expect(json_response['message']['path']).to eq(['has already been taken'])
expect(json_response['message']['name']).to eq(['has already been taken'])
end
end
context 'when unauthenticated' 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