summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngus MacArthur <amacarthur@blackberry.com>2013-03-28 11:59:48 -0400
committerAngus MacArthur <amacarthur@blackberry.com>2013-04-11 01:12:18 -0400
commita471d5526249654f93dae8d88b92c2cddb287178 (patch)
tree5f6b1b6d89285d2ae7439b2e70678b5894aba2c7
parent8e75018c538d422c8273e2dbcde65404fe8fd42b (diff)
downloadgitlab-shell-a471d5526249654f93dae8d88b92c2cddb287178.tar.gz
add fork_project command
-rw-r--r--lib/gitlab_projects.rb13
-rw-r--r--spec/gitlab_projects_spec.rb13
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
index aef343e..3115868 100644
--- a/lib/gitlab_projects.rb
+++ b/lib/gitlab_projects.rb
@@ -29,6 +29,7 @@ class GitlabProjects
when 'rm-project'; rm_project
when 'mv-project'; mv_project
when 'import-project'; import_project
+ when 'fork-project'; fork_project
else
puts 'not allowed'
false
@@ -84,4 +85,16 @@ class GitlabProjects
FileUtils.mv(full_path, new_full_path)
end
+
+ def fork_project
+ new_namespace = ARGV.shift
+
+ return false unless new_namespace
+
+ namespaced_path = File.join(repos_path, new_namespace)
+ return false unless File.exists?(namespaced_path)
+
+ cmd = "cd #{namespaced_path} && git clone --bare #{@full_path}"
+ system(cmd)
+ end
end
diff --git a/spec/gitlab_projects_spec.rb b/spec/gitlab_projects_spec.rb
index cbe1ab2..50d5023 100644
--- a/spec/gitlab_projects_spec.rb
+++ b/spec/gitlab_projects_spec.rb
@@ -18,7 +18,7 @@ describe GitlabProjects do
it { @gl_projects.project_name.should == repo_name }
it { @gl_projects.instance_variable_get(:@command).should == 'add-project' }
- it { @gl_projects.instance_variable_get(:@full_path).should == '/home/git/repositories/gitlab-ci.git' }
+ it { @gl_projects.instance_variable_get(:@full_path).should == "#{GitlabConfig.new.repos_path}/gitlab-ci.git" }
end
describe :add_project do
@@ -77,6 +77,17 @@ describe GitlabProjects do
end
end
+ describe :fork_project do
+ let(:gl_projects) { build_gitlab_projects('fork-project', repo_name, 'forked-to-namespace')}
+
+ it "should fork the repo" do
+ gl_projects.exec
+ File.exists?(File.join(tmp_repo_path, 'forked-to-namespace', repo_name))
+ File.exists?(File.join(tmp_repo_path, 'forked-to-namespace', repo_name, '/hooks/update/post-receive'))
+ File.exists?(File.join(tmp_repo_path, 'forked-to-namespace', repo_name, '/hooks/update/'))
+ end
+ end
+
describe :exec do
it 'should puts message if unknown command arg' do
gitlab_projects = build_gitlab_projects('edit-project', repo_name)