summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG1
-rw-r--r--lib/tasks/gitlab/git.rake52
-rw-r--r--lib/tasks/gitlab/task_helpers.rake4
3 files changed, 57 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 31feb115d1e..2c98b092e1b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -62,6 +62,7 @@ v 8.0.4
- Fix "Assign All" button on Runner admin page
- Fix search in Files
- Add full project namespace to payload of system webhooks (Ricardo Band)
+ - Add rake tasks for git repository maintainance (Zeger-Jan van de Weg)
v 8.0.3
- Fix URL shown in Slack notifications
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