diff options
author | Zeger-Jan van de Weg <mail@zjvandeweg.nl> | 2015-09-22 14:04:14 +0200 |
---|---|---|
committer | Zeger-Jan van de Weg <mail@zjvandeweg.nl> | 2015-10-14 19:11:09 +0200 |
commit | 54e6c0045bb13c05cc5478cbdf47d3246bd9fe2b (patch) | |
tree | 882bbd5e45a6d73f7d6feeff71f8f03f14610f84 /lib/tasks | |
parent | a2f0a3650b03fcca3c8ca428ca1d2173197b4d22 (diff) | |
download | gitlab-ce-54e6c0045bb13c05cc5478cbdf47d3246bd9fe2b.tar.gz |
Added three rake tasks for repository maintainance
Tasks added:
gitlab:git:repack
gitlab:git:gc
gitlab:git:prune
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/gitlab/git.rake | 52 | ||||
-rw-r--r-- | lib/tasks/gitlab/task_helpers.rake | 4 |
2 files changed, 56 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/git.rake b/lib/tasks/gitlab/git.rake new file mode 100644 index 00000000000..4fbf5a9393c --- /dev/null +++ b/lib/tasks/gitlab/git.rake @@ -0,0 +1,52 @@ +namespace :gitlab do + namespace :git do + + desc "GitLab | Git | Repack" + task repack: :environment do + failures = perform_git_cmd('git repack -a --quiet', 'Git repack') + if failures.empty? + puts "Done".green + else + output_failures(failures) + end + end + + desc "GitLab | Git | Run gits garbage collection on all repo's" + task gc: :environment do + failures = perform_git_cmd('git gc --auto --quiet', "Garbage Collection") + if failures.empty? + puts "Done".green + else + output_failures(failures) + end + end + + desc "GitLab | Git | Git prune all repo's" + task prune: :environment do + failures = perform_git_cmd('git prune', 'Git Prune') + if failures.empty? + puts "Done".green + else + output_failures(failures) + end + end + + def perform_git_cmd(cmd, message) + puts "Starting #{message} on all repositories" + + failures = [] + all_repos.each do |r| + puts "Performing #{message} at #{r}" + failures << r unless system(*%w(#{cmd}), chdir: r) + end + + failures + end + + def output_failures(failures) + puts "The following repositories reported errors:".red + failures.each { |f| puts "- #{f}" } + end + + end +end diff --git a/lib/tasks/gitlab/task_helpers.rake b/lib/tasks/gitlab/task_helpers.rake index c95b6540ebc..77c41bf61cb 100644 --- a/lib/tasks/gitlab/task_helpers.rake +++ b/lib/tasks/gitlab/task_helpers.rake @@ -128,4 +128,8 @@ namespace :gitlab do false end end + + def all_repos + Dir.glob(File.join(Gitlab.config.gitlab_shell.repos_path, '**/*\.git')) + end end |