diff options
author | Nick Thomas <nick@gitlab.com> | 2017-11-30 21:19:25 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2017-12-01 12:52:47 +0000 |
commit | 2e44e3176fa726119ea9e74b62b14f540770425d (patch) | |
tree | 0a860cc696c9b2c9563c731debf607ff6d3aa8fd /lib/gitlab_projects.rb | |
parent | 76e75549b9bec9dee1e856969ef169a4450b3f30 (diff) | |
download | gitlab-shell-2e44e3176fa726119ea9e74b62b14f540770425d.tar.gz |
Add a 'fork-repository' command that works with hashed storage
The existing 'fork-project' command cannot work with hashed storage as
the source project basename differs from the destination repository
basename. It is deprecated by the addition of 'fork-repository' and should
be removed in the next major version.
Diffstat (limited to 'lib/gitlab_projects.rb')
-rw-r--r-- | lib/gitlab_projects.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb index 9586345..ad62cce 100644 --- a/lib/gitlab_projects.rb +++ b/lib/gitlab_projects.rb @@ -69,6 +69,8 @@ class GitlabProjects import_project when 'fork-project'; fork_project + when 'fork-repository'; + fork_repository when 'fetch-remote'; fetch_remote when 'push-branches'; @@ -360,6 +362,35 @@ class GitlabProjects end end + def fork_repository + from_path = full_path + + new_repos_path = ARGV.shift + new_full_path = ARGV.shift + + unless new_repos_path && new_full_path + $logger.error "fork-repository failed: no destination repository path provided." + return false + end + + to_path = File.join(new_repos_path, new_full_path) + + # The repository cannot already exist + if File.exists?(to_path) + $logger.error "fork-repository failed: destination repository <#{to_path}> already exists." + return false + end + + # Ensure the namepsace / hashed storage directory exists + FileUtils.mkdir_p(File.dirname(to_path), mode: 0770) + + $logger.info "Forking repository from <#{from_path}> to <#{to_path}>." + cmd = %W(git clone --bare -- #{from_path} #{to_path}) + system(*cmd) && self.class.create_hooks(to_path) + end + + # DEPRECATED in favour of fork_repository, which takes a source and destination + # repository path and so can work with hashed storage. Remove in v6.0.0 def fork_project destination_repos_path = ARGV.shift |