summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-07-26 21:03:15 +0000
committerDouwe Maan <douwe@gitlab.com>2016-07-26 21:03:15 +0000
commitccf949e17127d590b8c823d8f678e9b687718dda (patch)
treece87981b58125684e8ae03d4530329db865420dc
parent2e2af9ac3b79aff92afad0f3f8cee60646f1128b (diff)
parent6b1129ccc0e3728acca9434add63d237acfc4744 (diff)
downloadgitlab-shell-ccf949e17127d590b8c823d8f678e9b687718dda.tar.gz
Merge branch '51-gitlab-project-s-fork_project-command-doesn-t-work-if-the-project-is-being-forked-to-another-storage' into 'master'
Allow gitlab-project's fork-project command to fork projects between different repository storages Closes #51 See merge request !75
-rw-r--r--CHANGELOG3
-rw-r--r--lib/gitlab_projects.rb9
-rw-r--r--spec/gitlab_projects_spec.rb39
3 files changed, 43 insertions, 8 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 6c735ee..5135bb0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+v3.2.1
+ - Allow gitlab-project's fork-project command to fork projects between different repository storages
+
v3.2.0
- 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
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
index ad3d3b8..4e6f271 100644
--- a/lib/gitlab_projects.rb
+++ b/lib/gitlab_projects.rb
@@ -286,6 +286,13 @@ class GitlabProjects
end
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
# destination namespace must be provided
@@ -295,7 +302,7 @@ class GitlabProjects
end
# 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)
$logger.error "fork-project failed: destination namespace <#{namespaced_path}> does not exist."
return false
diff --git a/spec/gitlab_projects_spec.rb b/spec/gitlab_projects_spec.rb
index fc0909e..a06b4d6 100644
--- a/spec/gitlab_projects_spec.rb
+++ b/spec/gitlab_projects_spec.rb
@@ -3,7 +3,6 @@ require_relative '../lib/gitlab_projects'
describe GitlabProjects do
before do
- GitlabConfig.any_instance.stub(repos_path: tmp_repos_path)
FileUtils.mkdir_p(tmp_repos_path)
$logger = double('logger').as_null_object
end
@@ -254,15 +253,21 @@ describe GitlabProjects do
describe :fork_project do
let(:source_repo_name) { File.join('source-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') }
before do
gl_projects_import.exec
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)
+ $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.")
missing_arg.exec.should be_false
end
@@ -301,6 +306,29 @@ describe GitlabProjects do
FileUtils.mkdir_p(File.join(tmp_repos_path, 'forked-to-namespace'))
gl_projects_fork.exec.should be_true
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
describe :exec do
@@ -319,10 +347,7 @@ describe GitlabProjects do
def build_gitlab_projects(*args)
argv(*args)
- gl_projects = 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
+ GitlabProjects.new
end
def argv(*args)