Commit 04b51a2b892c9c675f638239a3fbfec39cdc4729
1 parent
fbe03c50
Exists in
master
and in
4 other branches
Improve activate_namespace task to build missing dirs and moving repos correctly
Showing
2 changed files
with
34 additions
and
4 deletions
Show diff stats
lib/gitlab/backend/gitolite.rb
... | ... | @@ -38,6 +38,12 @@ module Gitlab |
38 | 38 | config.admin_all_repo! |
39 | 39 | end |
40 | 40 | |
41 | + def update_repositories projects | |
42 | + config.apply do |config| | |
43 | + config.update_projects(projects) | |
44 | + end | |
45 | + end | |
46 | + | |
41 | 47 | alias_method :create_repository, :update_repository |
42 | 48 | end |
43 | 49 | end | ... | ... |
lib/tasks/gitlab/activate_namespaces.rake
1 | 1 | namespace :gitlab do |
2 | 2 | desc "GITLAB | Enable usernames and namespaces for user projects" |
3 | 3 | task activate_namespaces: :environment do |
4 | + print "\nUsernames for users:".yellow | |
5 | + | |
4 | 6 | User.find_each(batch_size: 500) do |user| |
5 | 7 | next if user.namespace |
6 | 8 | |
... | ... | @@ -14,6 +16,8 @@ namespace :gitlab do |
14 | 16 | end |
15 | 17 | end |
16 | 18 | |
19 | + print "\n\nDirs for groups:".yellow | |
20 | + | |
17 | 21 | Group.find_each(batch_size: 500) do |group| |
18 | 22 | if group.ensure_dir_exist |
19 | 23 | print '.'.green |
... | ... | @@ -22,23 +26,43 @@ namespace :gitlab do |
22 | 26 | end |
23 | 27 | end |
24 | 28 | |
29 | + print "\n\nMove projects from groups under groups dirs:".yellow | |
25 | 30 | git_path = Gitlab.config.git_base_path |
26 | 31 | |
27 | 32 | Project.where('namespace_id IS NOT NULL').find_each(batch_size: 500) do |project| |
28 | 33 | next unless project.group |
34 | + next if project.empty_repo? | |
29 | 35 | |
30 | 36 | group = project.group |
31 | 37 | |
32 | - next if File.exists?(File.join(git_path, project.path_with_namespace)) | |
38 | + puts "\n" | |
39 | + print " * #{project.name}: " | |
40 | + | |
41 | + new_path = File.join(git_path, project.path_with_namespace + '.git') | |
42 | + | |
43 | + if File.exists?(new_path) | |
44 | + print "ok. already at #{new_path}".cyan | |
45 | + next | |
46 | + end | |
47 | + | |
48 | + old_path = File.join(git_path, project.path + '.git') | |
33 | 49 | |
34 | - next unless File.exists?(File.join(git_path, project.path)) | |
50 | + unless File.exists?(old_path) | |
51 | + print "missing. not found at #{old_path}".red | |
52 | + next | |
53 | + end | |
35 | 54 | |
36 | 55 | begin |
37 | 56 | Gitlab::ProjectMover.new(project, '', group.path).execute |
38 | - print '.'.green | |
57 | + print "ok. Moved to #{new_path}".green | |
39 | 58 | rescue |
40 | - print 'F'.red | |
59 | + print "Failed moving to #{new_path}".red | |
41 | 60 | end |
42 | 61 | end |
62 | + | |
63 | + print "\n\nRebuild gitolite:".yellow | |
64 | + gitolite = Gitlab::Gitolite.new | |
65 | + gitolite.update_repositories(Project.where('namespace_id IS NOT NULL')) | |
66 | + puts "\n" | |
43 | 67 | end |
44 | 68 | end | ... | ... |