From: Dmitriy Zaporozhets Date: Mon, 24 Dec 2012 18:01:49 +0000 (+0200) Subject: Update projects in gitolite after namespace moved. Added rake task to cleanup garbage... X-Git-Tag: v4.1.0~210 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=a87fccc0834aa816289669a0fc7744338e469745;p=wvm%2Fgitlab.git Update projects in gitolite after namespace moved. Added rake task to cleanup garbage from gitolite --- diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 8c90f5aee..96f8f2914 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -27,10 +27,13 @@ class Namespace < ActiveRecord::Base after_create :ensure_dir_exist after_update :move_dir + after_commit :update_gitolite, on: :update, if: :require_update_gitolite after_destroy :rm_dir scope :root, where('type IS NULL') + attr_accessor :require_update_gitolite + def self.search query where("name LIKE :query OR path LIKE :query", query: "%#{query}%") end @@ -62,10 +65,18 @@ class Namespace < ActiveRecord::Base if system("mv #{old_path} #{new_path}") send_update_instructions + @require_update_gitolite = true + else + raise "Namespace move error #{old_path} #{new_path}" end end end + def update_gitolite + @require_update_gitolite = false + projects.each(&:update_repository) + end + def rm_dir dir_path = File.join(Gitlab.config.gitolite.repos_path, path) system("rm -rf #{dir_path}") diff --git a/app/roles/namespaced_project.rb b/app/roles/namespaced_project.rb index 8656890a4..dbd533f84 100644 --- a/app/roles/namespaced_project.rb +++ b/app/roles/namespaced_project.rb @@ -24,7 +24,7 @@ module NamespacedProject save! end rescue Gitlab::ProjectMover::ProjectMoveError => ex - raise TransferError.new(ex.message) + raise Project::TransferError.new(ex.message) end def name_with_namespace diff --git a/lib/tasks/gitlab/gitolite_rebuild.rake b/lib/tasks/gitlab/gitolite_rebuild.rake index af2a2127e..8fa466fbf 100644 --- a/lib/tasks/gitlab/gitolite_rebuild.rake +++ b/lib/tasks/gitlab/gitolite_rebuild.rake @@ -23,5 +23,38 @@ namespace :gitlab do puts "... #{"done".green}" end end + + desc "GITLAB | Cleanup gitolite config" + task :cleanup => :environment do + warn_user_is_not_gitlab + + real_repos = Project.all.map(&:path_with_namespace) + real_repos << "gitolite-admin" + real_repos << "@all" + + remove_flag = ENV['REMOVE'] + + puts "Looking for repositories to remove... " + Gitlab::GitoliteConfig.new.apply do |config| + all_repos = [] + garbage_repos = [] + + all_repos = config.conf.repos.keys + garbage_repos = all_repos - real_repos + + garbage_repos.each do |repo_name| + if remove_flag + config.conf.rm_repo(repo_name) + print "to remove...".red + end + + puts repo_name.red + end + end + + unless remove_flag + puts "To cleanup repositories run this command with REMOVE=true".yellow + end + end end end