gitlab-org--gitlab-foss/lib/tasks/gitlab/git.rake
Zeger-Jan van de Weg 54e6c0045b Added three rake tasks for repository maintainance
Tasks added:
gitlab:git:repack
gitlab:git:gc
gitlab:git:prune
2015-10-14 19:11:09 +02:00

52 lines
1.2 KiB
Ruby

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