Commit 522567af authored by Alejandro Rodríguez's avatar Alejandro Rodríguez

Add command to move repositories between repository storages

parent 87b38823
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
......
......@@ -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
......
......@@ -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') }
......
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