Commit 26147a3a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

mv-project feature added

parent 9d03bb10
......@@ -11,6 +11,8 @@ require_relative '../lib/gitlab_init'
#
# /bin/gitlab-projects rm-project gitlab/gitlab-ci.git
#
# /bin/gitlab-projects mv-project gitlab/gitlab-ci.git randx/fork.git
#
# /bin/gitlab-projects import-project randx/six.git https://github.com/randx/six.git
#
require File.join(ROOT_PATH, 'lib', 'gitlab_projects')
......
......@@ -27,6 +27,7 @@ class GitlabProjects
case @command
when 'add-project'; add_project
when 'rm-project'; rm_project
when 'mv-project'; mv_project
when 'import-project'; import_project
else
puts 'not allowed'
......@@ -52,9 +53,34 @@ class GitlabProjects
FileUtils.rm_rf(full_path)
end
# Import project via git clone --bare
# URL must be publicly clonable
def import_project
@source = ARGV.shift
cmd = "cd #{repos_path} && git clone --bare #{@source} #{project_name} && #{create_hooks_cmd}"
system(cmd)
end
# Move repository from one directory to another
#
# Ex.
# gitlab.git -> gitlabhq.git
# gitlab/gitlab-ci.git -> randx/six.git
#
# Wont work if target namespace directory does not exist
#
def mv_project
new_path = ARGV.shift
return false unless new_path
new_full_path = File.join(repos_path, new_path)
# check if source repo exists
# and target repo does not exist
return false unless File.exists?(full_path)
return false if File.exists?(new_full_path)
FileUtils.mv(full_path, new_full_path)
end
end
......@@ -39,6 +39,21 @@ describe GitlabProjects do
end
end
describe :mv_project do
let(:gl_projects) { build_gitlab_projects('mv-project', repo_name, 'repo.git') }
before do
FileUtils.mkdir_p(tmp_repo_path)
end
it "should move a repo directory" do
File.exists?(tmp_repo_path).should be_true
gl_projects.exec
File.exists?(tmp_repo_path).should be_false
File.exists?(File.join(tmp_repos_path, 'repo.git')).should be_true
end
end
describe :rm_project do
let(:gl_projects) { build_gitlab_projects('rm-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