From 93e702dd6473f38f8da98d1253d1b2d6e01cf37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vanja=20Radovanovi=C4=87?= Date: Wed, 12 Sep 2012 10:06:57 +0200 Subject: [PATCH] added rake task to cleanup/maintain (git gc) repositories --- lib/tasks/cleanup_repositories.rake | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lib/tasks/cleanup_repositories.rake diff --git a/lib/tasks/cleanup_repositories.rake b/lib/tasks/cleanup_repositories.rake new file mode 100644 index 00000000000..a46de584cd2 --- /dev/null +++ b/lib/tasks/cleanup_repositories.rake @@ -0,0 +1,27 @@ +desc "Cleanup repositories for all projects" +task :cleanup_repositories => :environment do |t, args| + cleaned_count, failed_count = 0, 0 + + Project.all.each do |project| + if cleanup_repository_for_project(project) + cleaned_count += 1 + else + failed_count += 1 + end + end + + puts "Finished cleaning #{cleaned_count} repositories (failed #{failed_count})." +end + +def cleanup_repository_for_project(project) + git_user = Gitlab.config.ssh_user + git_command = "git gc" + begin + sh "sudo -u #{git_user} -i cd #{project.path_to_repo} && #{git_command}" + true + rescue Exception => msg + puts " ERROR: Failed to #{git_command} @ #{project.path} as #{git_user} user" + puts " Exception-MSG: #{msg}" + false + end +end -- GitLab