Commit a471d552 authored by Angus MacArthur's avatar Angus MacArthur

add fork_project command

parent 8e75018c
...@@ -29,6 +29,7 @@ class GitlabProjects ...@@ -29,6 +29,7 @@ class GitlabProjects
when 'rm-project'; rm_project when 'rm-project'; rm_project
when 'mv-project'; mv_project when 'mv-project'; mv_project
when 'import-project'; import_project when 'import-project'; import_project
when 'fork-project'; fork_project
else else
puts 'not allowed' puts 'not allowed'
false false
...@@ -84,4 +85,16 @@ class GitlabProjects ...@@ -84,4 +85,16 @@ class GitlabProjects
FileUtils.mv(full_path, new_full_path) FileUtils.mv(full_path, new_full_path)
end 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 end
...@@ -18,7 +18,7 @@ describe GitlabProjects do ...@@ -18,7 +18,7 @@ describe GitlabProjects do
it { @gl_projects.project_name.should == repo_name } it { @gl_projects.project_name.should == repo_name }
it { @gl_projects.instance_variable_get(:@command).should == 'add-project' } 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 end
describe :add_project do describe :add_project do
...@@ -77,6 +77,17 @@ describe GitlabProjects do ...@@ -77,6 +77,17 @@ describe GitlabProjects do
end end
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 describe :exec do
it 'should puts message if unknown command arg' do it 'should puts message if unknown command arg' do
gitlab_projects = build_gitlab_projects('edit-project', repo_name) gitlab_projects = build_gitlab_projects('edit-project', repo_name)
......
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