Commit 6b1129cc authored by Alejandro Rodríguez's avatar Alejandro Rodríguez

Allow gitlab-project's fork-project command to fork projects between different repository storages

parent 2e2af9ac
v3.2.1
- Allow gitlab-project's fork-project command to fork projects between different repository storages
v3.2.0 v3.2.0
- Allow GitLab Shell to check for allowed access based on the used Git protocol - Allow GitLab Shell to check for allowed access based on the used Git protocol
- Add an error message when using shell commands with incompatible GitLab versions - Add an error message when using shell commands with incompatible GitLab versions
......
...@@ -286,6 +286,13 @@ class GitlabProjects ...@@ -286,6 +286,13 @@ class GitlabProjects
end end
def fork_project def fork_project
destination_repos_path = ARGV.shift
unless destination_repos_path
$logger.error "fork-project failed: no destination repository path provided."
return false
end
new_namespace = ARGV.shift new_namespace = ARGV.shift
# destination namespace must be provided # destination namespace must be provided
...@@ -295,7 +302,7 @@ class GitlabProjects ...@@ -295,7 +302,7 @@ class GitlabProjects
end end
# destination namespace must exist # destination namespace must exist
namespaced_path = File.join(repos_path, new_namespace) namespaced_path = File.join(destination_repos_path, new_namespace)
unless File.exists?(namespaced_path) unless File.exists?(namespaced_path)
$logger.error "fork-project failed: destination namespace <#{namespaced_path}> does not exist." $logger.error "fork-project failed: destination namespace <#{namespaced_path}> does not exist."
return false return false
......
...@@ -3,7 +3,6 @@ require_relative '../lib/gitlab_projects' ...@@ -3,7 +3,6 @@ require_relative '../lib/gitlab_projects'
describe GitlabProjects do describe GitlabProjects do
before do before do
GitlabConfig.any_instance.stub(repos_path: tmp_repos_path)
FileUtils.mkdir_p(tmp_repos_path) FileUtils.mkdir_p(tmp_repos_path)
$logger = double('logger').as_null_object $logger = double('logger').as_null_object
end end
...@@ -254,15 +253,21 @@ describe GitlabProjects do ...@@ -254,15 +253,21 @@ describe GitlabProjects do
describe :fork_project do describe :fork_project do
let(:source_repo_name) { File.join('source-namespace', repo_name) } let(:source_repo_name) { File.join('source-namespace', repo_name) }
let(:dest_repo) { File.join(tmp_repos_path, 'forked-to-namespace', repo_name) } let(:dest_repo) { File.join(tmp_repos_path, 'forked-to-namespace', repo_name) }
let(:gl_projects_fork) { build_gitlab_projects('fork-project', tmp_repos_path, source_repo_name, 'forked-to-namespace') } let(:gl_projects_fork) { build_gitlab_projects('fork-project', tmp_repos_path, source_repo_name, tmp_repos_path, 'forked-to-namespace') }
let(:gl_projects_import) { build_gitlab_projects('import-project', tmp_repos_path, source_repo_name, 'https://github.com/randx/six.git') } let(:gl_projects_import) { build_gitlab_projects('import-project', tmp_repos_path, source_repo_name, 'https://github.com/randx/six.git') }
before do before do
gl_projects_import.exec gl_projects_import.exec
end end
it "should not fork without a destination namespace" do it "should not fork without a source repository path" do
missing_arg = build_gitlab_projects('fork-project', tmp_repos_path, source_repo_name) missing_arg = build_gitlab_projects('fork-project', tmp_repos_path, source_repo_name)
$logger.should_receive(:error).with("fork-project failed: no destination repository path provided.")
missing_arg.exec.should be_false
end
it "should not fork without a destination namespace" do
missing_arg = build_gitlab_projects('fork-project', tmp_repos_path, source_repo_name, tmp_repos_path)
$logger.should_receive(:error).with("fork-project failed: no destination namespace provided.") $logger.should_receive(:error).with("fork-project failed: no destination namespace provided.")
missing_arg.exec.should be_false missing_arg.exec.should be_false
end end
...@@ -301,6 +306,29 @@ describe GitlabProjects do ...@@ -301,6 +306,29 @@ describe GitlabProjects do
FileUtils.mkdir_p(File.join(tmp_repos_path, 'forked-to-namespace')) FileUtils.mkdir_p(File.join(tmp_repos_path, 'forked-to-namespace'))
gl_projects_fork.exec.should be_true gl_projects_fork.exec.should be_true
end end
context 'different storages' do
let(:alternative_repos_path) { File.join(ROOT_PATH, 'tmp', 'alternative') }
let(:dest_repo) { File.join(alternative_repos_path, 'forked-to-namespace', repo_name) }
let(:gl_projects_fork) { build_gitlab_projects('fork-project', tmp_repos_path, source_repo_name, alternative_repos_path, 'forked-to-namespace') }
before do
FileUtils.mkdir_p(alternative_repos_path)
end
after do
FileUtils.rm_rf(alternative_repos_path)
end
it "should fork the repo" do
# create destination namespace
FileUtils.mkdir_p(File.join(alternative_repos_path, 'forked-to-namespace'))
gl_projects_fork.exec.should be_true
File.exists?(dest_repo).should be_true
File.exists?(File.join(dest_repo, '/hooks/pre-receive')).should be_true
File.exists?(File.join(dest_repo, '/hooks/post-receive')).should be_true
end
end
end end
describe :exec do describe :exec do
...@@ -319,10 +347,7 @@ describe GitlabProjects do ...@@ -319,10 +347,7 @@ describe GitlabProjects do
def build_gitlab_projects(*args) def build_gitlab_projects(*args)
argv(*args) argv(*args)
gl_projects = GitlabProjects.new GitlabProjects.new
gl_projects.stub(repos_path: tmp_repos_path)
gl_projects.stub(full_path: File.join(tmp_repos_path, gl_projects.project_name))
gl_projects
end end
def argv(*args) def argv(*args)
......
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