2015-09-22 08:04:14 -04:00
|
|
|
namespace :gitlab do
|
|
|
|
namespace :git do
|
|
|
|
desc "GitLab | Git | Repack"
|
|
|
|
task repack: :environment do
|
2017-01-05 07:46:26 -05:00
|
|
|
failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} repack -a --quiet), "Repacking repo")
|
2015-09-22 08:04:14 -04:00
|
|
|
if failures.empty?
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "Done".color(:green)
|
2015-09-22 08:04:14 -04:00
|
|
|
else
|
|
|
|
output_failures(failures)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-01 07:34:41 -04:00
|
|
|
desc "GitLab | Git | Run garbage collection on all repos"
|
2015-09-22 08:04:14 -04:00
|
|
|
task gc: :environment do
|
2017-01-05 07:46:26 -05:00
|
|
|
failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} gc --auto --quiet), "Garbage Collecting")
|
2015-09-22 08:04:14 -04:00
|
|
|
if failures.empty?
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "Done".color(:green)
|
2015-09-22 08:04:14 -04:00
|
|
|
else
|
|
|
|
output_failures(failures)
|
|
|
|
end
|
|
|
|
end
|
2017-01-05 07:46:26 -05:00
|
|
|
|
2015-10-01 07:34:41 -04:00
|
|
|
desc "GitLab | Git | Prune all repos"
|
2015-09-22 08:04:14 -04:00
|
|
|
task prune: :environment do
|
2017-01-05 07:46:26 -05:00
|
|
|
failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} prune), "Git Prune")
|
2015-09-22 08:04:14 -04:00
|
|
|
if failures.empty?
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "Done".color(:green)
|
2015-09-22 08:04:14 -04:00
|
|
|
else
|
|
|
|
output_failures(failures)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-14 05:49:35 -05:00
|
|
|
desc 'GitLab | Git | Check all repos integrity'
|
|
|
|
task fsck: :environment do
|
2018-01-03 08:51:04 -05:00
|
|
|
failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} fsck --name-objects --no-progress), "Checking integrity") do |repo|
|
|
|
|
check_config_lock(repo)
|
|
|
|
check_ref_locks(repo)
|
|
|
|
end
|
2018-01-04 05:02:43 -05:00
|
|
|
|
2017-12-14 05:49:35 -05:00
|
|
|
if failures.empty?
|
|
|
|
puts "Done".color(:green)
|
|
|
|
else
|
|
|
|
output_failures(failures)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-22 08:04:14 -04:00
|
|
|
def perform_git_cmd(cmd, message)
|
|
|
|
puts "Starting #{message} on all repositories"
|
|
|
|
|
|
|
|
failures = []
|
2015-10-01 07:34:41 -04:00
|
|
|
all_repos do |repo|
|
|
|
|
if system(*cmd, chdir: repo)
|
|
|
|
puts "Performed #{message} at #{repo}"
|
|
|
|
else
|
|
|
|
failures << repo
|
|
|
|
end
|
2018-01-03 08:51:04 -05:00
|
|
|
|
|
|
|
yield(repo) if block_given?
|
2015-09-22 08:04:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
failures
|
|
|
|
end
|
|
|
|
|
|
|
|
def output_failures(failures)
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "The following repositories reported errors:".color(:red)
|
2015-09-22 08:04:14 -04:00
|
|
|
failures.each { |f| puts "- #{f}" }
|
|
|
|
end
|
2018-01-03 08:51:04 -05:00
|
|
|
|
|
|
|
def check_config_lock(repo_dir)
|
|
|
|
config_exists = File.exist?(File.join(repo_dir, 'config.lock'))
|
|
|
|
config_output = config_exists ? 'yes'.color(:red) : 'no'.color(:green)
|
|
|
|
|
|
|
|
puts "'config.lock' file exists?".color(:yellow) + " ... #{config_output}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_ref_locks(repo_dir)
|
|
|
|
lock_files = Dir.glob(File.join(repo_dir, 'refs/heads/*.lock'))
|
|
|
|
|
|
|
|
if lock_files.present?
|
|
|
|
puts "Ref lock files exist:".color(:red)
|
|
|
|
|
|
|
|
lock_files.each { |lock_file| puts " #{lock_file}" }
|
|
|
|
else
|
|
|
|
puts "No ref lock files exist".color(:green)
|
|
|
|
end
|
|
|
|
end
|
2015-09-22 08:04:14 -04:00
|
|
|
end
|
|
|
|
end
|