summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-12 12:37:53 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-12 12:37:53 +0200
commit59b36f203274bedf6d455968d49af8fdba5e40ef (patch)
tree3e1d8fddc82b69d63b3f31ba87f71e34a99638a2 /lib
parentb1e425511fd9f79da5289f1651bb8e9397b384f5 (diff)
downloadgitlab-ce-59b36f203274bedf6d455968d49af8fdba5e40ef.tar.gz
Use gitlab-shell to move repos. Requires gitlab-shell v1.1.0
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/backend/shell.rb14
-rw-r--r--lib/gitlab/project_mover.rb45
2 files changed, 13 insertions, 46 deletions
diff --git a/lib/gitlab/backend/shell.rb b/lib/gitlab/backend/shell.rb
index 9ea08ccbdbf..a230886b47c 100644
--- a/lib/gitlab/backend/shell.rb
+++ b/lib/gitlab/backend/shell.rb
@@ -24,6 +24,18 @@ module Gitlab
system("#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects import-project #{name}.git #{url}")
end
+ # Move repository
+ #
+ # path - project path with namespace
+ # new_path - new project path with namespace
+ #
+ # Ex.
+ # mv_repository("gitlab/gitlab-ci", "randx/gitlab-ci-new.git")
+ #
+ def mv_repository(path, new_path)
+ system("#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects mv-project #{path}.git #{new_path}.git")
+ end
+
# Remove repository from file system
#
# name - project path with namespace
@@ -56,7 +68,7 @@ module Gitlab
def url_to_repo path
Gitlab.config.gitlab_shell.ssh_path_prefix + "#{path}.git"
end
-
+
def gitlab_shell_user_home
File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}")
end
diff --git a/lib/gitlab/project_mover.rb b/lib/gitlab/project_mover.rb
deleted file mode 100644
index e21f45c6564..00000000000
--- a/lib/gitlab/project_mover.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-# ProjectMover class
-#
-# Used for moving project repositories from one subdir to another
-module Gitlab
- class ProjectMover
- class ProjectMoveError < StandardError; end
-
- attr_reader :project, :old_dir, :new_dir
-
- def initialize(project, old_dir, new_dir)
- @project = project
- @old_dir = old_dir
- @new_dir = new_dir
- end
-
- def execute
- # Create new dir if missing
- new_dir_path = File.join(Gitlab.config.gitlab_shell.repos_path, new_dir)
- FileUtils.mkdir( new_dir_path, mode: 0770 ) unless File.exists?(new_dir_path)
-
- old_path = File.join(Gitlab.config.gitlab_shell.repos_path, old_dir, "#{project.path}.git")
- new_path = File.join(new_dir_path, "#{project.path}.git")
-
- if File.exists? new_path
- raise ProjectMoveError.new("Destination #{new_path} already exists")
- end
-
- begin
- FileUtils.mv( old_path, new_path )
- log_info "Project #{project.name} was moved from #{old_path} to #{new_path}"
- true
- rescue Exception => e
- message = "Project #{project.name} cannot be moved from #{old_path} to #{new_path}"
- log_info "Error! #{message} (#{e.message})"
- raise ProjectMoveError.new(message)
- end
- end
-
- protected
-
- def log_info message
- Gitlab::AppLogger.info message
- end
- end
-end