summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG3
-rw-r--r--lib/gitlab_projects.rb32
-rw-r--r--spec/gitlab_projects_spec.rb37
3 files changed, 72 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 5135bb0..95a348f 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+v3.3.0
+ - Add command to move repositories between repository storages
+
v3.2.1
- Allow gitlab-project's fork-project command to fork projects between different repository storages
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
index 4e6f271..0f643b0 100644
--- a/lib/gitlab_projects.rb
+++ b/lib/gitlab_projects.rb
@@ -55,6 +55,7 @@ class GitlabProjects
when 'list-projects'; puts list_projects
when 'rm-project'; rm_project
when 'mv-project'; mv_project
+ when 'mv-storage'; mv_storage
when 'import-project'; import_project
when 'fork-project'; fork_project
when 'fetch-remote'; fetch_remote
@@ -285,6 +286,37 @@ class GitlabProjects
FileUtils.mv(full_path, new_full_path)
end
+ # Move repository from one storage path to another
+ #
+ # Wont work if target namespace directory does not exist in the new storage path
+ #
+ def mv_storage
+ new_storage = ARGV.shift
+
+ unless new_storage
+ $logger.error "mv-storage failed: no destination storage path provided."
+ return false
+ end
+
+ new_full_path = File.join(new_storage, project_name)
+
+ # verify that the source repo exists
+ unless File.exists?(full_path)
+ $logger.error "mv-storage failed: source path <#{full_path}> does not exist."
+ return false
+ end
+
+ # Make sure the destination directory exists
+ FileUtils.mkdir_p(new_full_path)
+
+ # Make sure the source path ends with a slash so that rsync copies the
+ # contents of the directory, as opposed to copying the directory by name
+ source_path = File.join(full_path, '')
+
+ $logger.info "Syncing project #{@project_name} from <#{full_path}> to <#{new_full_path}>."
+ system(*%W(rsync -a #{source_path} #{new_full_path}))
+ end
+
def fork_project
destination_repos_path = ARGV.shift
diff --git a/spec/gitlab_projects_spec.rb b/spec/gitlab_projects_spec.rb
index a06b4d6..5e50af0 100644
--- a/spec/gitlab_projects_spec.rb
+++ b/spec/gitlab_projects_spec.rb
@@ -205,6 +205,43 @@ describe GitlabProjects do
end
end
+ describe :mv_storage do
+ let(:alternative_storage_path) { File.join(ROOT_PATH, 'tmp', 'alternative') }
+ let(:gl_projects) { build_gitlab_projects('mv-storage', tmp_repos_path, repo_name, alternative_storage_path) }
+ let(:new_repo_path) { File.join(alternative_storage_path, repo_name) }
+
+ before do
+ FileUtils.mkdir_p(tmp_repo_path)
+ FileUtils.mkdir_p(alternative_storage_path)
+ end
+
+ after { FileUtils.rm_rf(alternative_storage_path) }
+
+ it "should rsync a repo directory" do
+ File.exists?(tmp_repo_path).should be_true
+ gl_projects.exec
+ File.exists?(new_repo_path).should be_true
+ end
+
+ it "should fail if no destination path is provided" do
+ incomplete = build_gitlab_projects('mv-storage', tmp_repos_path, repo_name)
+ $logger.should_receive(:error).with("mv-storage failed: no destination storage path provided.")
+ incomplete.exec.should be_false
+ end
+
+ it "should fail if the source path doesn't exist" do
+ bad_source = build_gitlab_projects('mv-storage', tmp_repos_path, 'bad-src.git', alternative_storage_path)
+ $logger.should_receive(:error).with("mv-storage failed: source path <#{tmp_repos_path}/bad-src.git> does not exist.")
+ bad_source.exec.should be_false
+ end
+
+ it "should log an mv-storage event" do
+ message = "Syncing project #{repo_name} from <#{tmp_repo_path}> to <#{new_repo_path}>."
+ $logger.should_receive(:info).with(message)
+ gl_projects.exec
+ end
+ end
+
describe :import_project do
context 'success import' do
let(:gl_projects) { build_gitlab_projects('import-project', tmp_repos_path, repo_name, 'https://github.com/randx/six.git') }