summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/gitlab-projects2
-rw-r--r--lib/gitlab_projects.rb26
-rw-r--r--spec/gitlab_projects_spec.rb15
3 files changed, 43 insertions, 0 deletions
diff --git a/bin/gitlab-projects b/bin/gitlab-projects
index 3f7a102..21e4305 100755
--- a/bin/gitlab-projects
+++ b/bin/gitlab-projects
@@ -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')
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
index 1b23438..8ef967a 100644
--- a/lib/gitlab_projects.rb
+++ b/lib/gitlab_projects.rb
@@ -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
diff --git a/spec/gitlab_projects_spec.rb b/spec/gitlab_projects_spec.rb
index a9eb15f..cbe1ab2 100644
--- a/spec/gitlab_projects_spec.rb
+++ b/spec/gitlab_projects_spec.rb
@@ -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) }