diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2015-12-08 16:05:49 +0000 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2015-12-08 16:05:49 +0000 |
commit | a80f0f66e3c55e9793007bad6162eabba5c8582c (patch) | |
tree | 1742ca4b3f12e650f233b209c318bf57bddf8d9c | |
parent | 4cd259e91dd54cda479d114210c6b7dc9113a5cc (diff) | |
parent | 3da32ef7d84f5800434379520878fe5c186b9e39 (diff) | |
download | gitlab-ce-a80f0f66e3c55e9793007bad6162eabba5c8582c.tar.gz |
Merge branch 'rake-tasks-git' into 'master'
Added 3 rake tasks for repository maintainance
## What does this MR do?
This MR adds 3 rake tasks
- gitlab:git:repack
- `-a`
- `--quiet`
- gitlab:git:gc
- `--auto`
- `--quiet`
- gitlab:git:prune
- Needs git version > 1.8.4.1, Ubuntu repos @ 1.9.x
## Are there points in the code the reviewer needs to double check?
AFAIK this MR abides by the Guidelines for shell commands. Also, the output given is not the diskspace saved etc, just if the commands were succesfull. (Parsing output etc did not seem like the way to go)
Output might be verbose when a lot of repo's are in the system?
## Why was this MR needed?
`git gc` and `git prune` can reduce storage space used.
## What are the relevant issue numbers / Feature requests?
Closes #1529
## Screenshots (if relevant)
`rake -T`

(git fsck now removed as IMHO it doesn't add any value.)
See merge request !1388
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | lib/tasks/gitlab/git.rake | 55 | ||||
-rw-r--r-- | lib/tasks/gitlab/task_helpers.rake | 8 |
3 files changed, 64 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG index f4f9332b502..ebb994a651c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ v 8.3.0 (unreleased) - Fix API setting of 'public' attribute to false will make a project private (Stan Hu) - Handle and report SSL errors in Web hook test (Stan Hu) - Fix: Assignee selector is empty when 'Unassigned' is selected (Jose Corcuera) + - Add rake tasks for git repository maintainance (Zeger-Jan van de Weg) - Fix 500 error when update group member permission - Trim leading and trailing whitespace of milestone and issueable titles (Jose Corcuera) - Recognize issue/MR/snippet/commit links as references diff --git a/lib/tasks/gitlab/git.rake b/lib/tasks/gitlab/git.rake new file mode 100644 index 00000000000..65ee430d550 --- /dev/null +++ b/lib/tasks/gitlab/git.rake @@ -0,0 +1,55 @@ +namespace :gitlab do + namespace :git do + + desc "GitLab | Git | Repack" + task repack: :environment do + failures = perform_git_cmd(%W(git repack -a --quiet), "Repacking repo") + if failures.empty? + puts "Done".green + else + output_failures(failures) + end + end + + desc "GitLab | Git | Run garbage collection on all repos" + task gc: :environment do + failures = perform_git_cmd(%W(git gc --auto --quiet), "Garbage Collecting") + if failures.empty? + puts "Done".green + else + output_failures(failures) + end + end + + desc "GitLab | Git | Prune all repos" + task prune: :environment do + failures = perform_git_cmd(%W(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 do |repo| + if system(*cmd, chdir: repo) + puts "Performed #{message} at #{repo}" + else + failures << repo + end + 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 efb863a8764..ebe516ec879 100644 --- a/lib/tasks/gitlab/task_helpers.rake +++ b/lib/tasks/gitlab/task_helpers.rake @@ -118,4 +118,12 @@ namespace :gitlab do false end end + + def all_repos + IO.popen(%W(find #{Gitlab.config.gitlab_shell.repos_path} -mindepth 2 -maxdepth 2 -type d -name *.git)) do |find| + find.each_line do |path| + yield path.chomp + end + end + end end |