Commit a87fccc0834aa816289669a0fc7744338e469745
1 parent
dea86281
Exists in
master
and in
4 other branches
Update projects in gitolite after namespace moved. Added rake task to cleanup garbage from gitolite
Showing
3 changed files
with
45 additions
and
1 deletions
Show diff stats
app/models/namespace.rb
| ... | ... | @@ -27,10 +27,13 @@ class Namespace < ActiveRecord::Base |
| 27 | 27 | |
| 28 | 28 | after_create :ensure_dir_exist |
| 29 | 29 | after_update :move_dir |
| 30 | + after_commit :update_gitolite, on: :update, if: :require_update_gitolite | |
| 30 | 31 | after_destroy :rm_dir |
| 31 | 32 | |
| 32 | 33 | scope :root, where('type IS NULL') |
| 33 | 34 | |
| 35 | + attr_accessor :require_update_gitolite | |
| 36 | + | |
| 34 | 37 | def self.search query |
| 35 | 38 | where("name LIKE :query OR path LIKE :query", query: "%#{query}%") |
| 36 | 39 | end |
| ... | ... | @@ -62,10 +65,18 @@ class Namespace < ActiveRecord::Base |
| 62 | 65 | |
| 63 | 66 | if system("mv #{old_path} #{new_path}") |
| 64 | 67 | send_update_instructions |
| 68 | + @require_update_gitolite = true | |
| 69 | + else | |
| 70 | + raise "Namespace move error #{old_path} #{new_path}" | |
| 65 | 71 | end |
| 66 | 72 | end |
| 67 | 73 | end |
| 68 | 74 | |
| 75 | + def update_gitolite | |
| 76 | + @require_update_gitolite = false | |
| 77 | + projects.each(&:update_repository) | |
| 78 | + end | |
| 79 | + | |
| 69 | 80 | def rm_dir |
| 70 | 81 | dir_path = File.join(Gitlab.config.gitolite.repos_path, path) |
| 71 | 82 | system("rm -rf #{dir_path}") | ... | ... |
app/roles/namespaced_project.rb
lib/tasks/gitlab/gitolite_rebuild.rake
| ... | ... | @@ -23,5 +23,38 @@ namespace :gitlab do |
| 23 | 23 | puts "... #{"done".green}" |
| 24 | 24 | end |
| 25 | 25 | end |
| 26 | + | |
| 27 | + desc "GITLAB | Cleanup gitolite config" | |
| 28 | + task :cleanup => :environment do | |
| 29 | + warn_user_is_not_gitlab | |
| 30 | + | |
| 31 | + real_repos = Project.all.map(&:path_with_namespace) | |
| 32 | + real_repos << "gitolite-admin" | |
| 33 | + real_repos << "@all" | |
| 34 | + | |
| 35 | + remove_flag = ENV['REMOVE'] | |
| 36 | + | |
| 37 | + puts "Looking for repositories to remove... " | |
| 38 | + Gitlab::GitoliteConfig.new.apply do |config| | |
| 39 | + all_repos = [] | |
| 40 | + garbage_repos = [] | |
| 41 | + | |
| 42 | + all_repos = config.conf.repos.keys | |
| 43 | + garbage_repos = all_repos - real_repos | |
| 44 | + | |
| 45 | + garbage_repos.each do |repo_name| | |
| 46 | + if remove_flag | |
| 47 | + config.conf.rm_repo(repo_name) | |
| 48 | + print "to remove...".red | |
| 49 | + end | |
| 50 | + | |
| 51 | + puts repo_name.red | |
| 52 | + end | |
| 53 | + end | |
| 54 | + | |
| 55 | + unless remove_flag | |
| 56 | + puts "To cleanup repositories run this command with REMOVE=true".yellow | |
| 57 | + end | |
| 58 | + end | |
| 26 | 59 | end |
| 27 | 60 | end | ... | ... |