diff options
author | Alejandro RodrÃguez <alejorro70@gmail.com> | 2016-07-19 17:22:13 -0400 |
---|---|---|
committer | Alejandro RodrÃguez <alejorro70@gmail.com> | 2016-07-27 11:13:19 -0400 |
commit | 522567afca91f2e04871e3d9bf8e9884f48a9855 (patch) | |
tree | 6dde32311a141eb97634c801397052541514ae2b /lib | |
parent | 87b388232505b1715a1d7448dc393a383cd7a53f (diff) | |
download | gitlab-shell-522567afca91f2e04871e3d9bf8e9884f48a9855.tar.gz |
Add command to move repositories between repository storages
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab_projects.rb | 32 |
1 files changed, 32 insertions, 0 deletions
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 |