BigW Consortium Gitlab

git.rake 1.38 KB
Newer Older
1 2 3 4 5
namespace :gitlab do
  namespace :git do

    desc "GitLab | Git | Repack"
    task repack: :environment do
6
      failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} repack -a --quiet), "Repacking repo")
7
      if failures.empty?
8
        puts "Done".color(:green)
9 10 11 12 13
      else
        output_failures(failures)
      end
    end

14
    desc "GitLab | Git | Run garbage collection on all repos"
15
    task gc: :environment do
16
      failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} gc --auto --quiet), "Garbage Collecting")
17
      if failures.empty?
18
        puts "Done".color(:green)
19 20 21 22
      else
        output_failures(failures)
      end
    end
23

24
    desc "GitLab | Git | Prune all repos"
25
    task prune: :environment do
26
      failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} prune), "Git Prune")
27
      if failures.empty?
28
        puts "Done".color(:green)
29 30 31 32 33 34 35 36 37
      else
        output_failures(failures)
      end
    end

    def perform_git_cmd(cmd, message)
      puts "Starting #{message} on all repositories"

      failures = []
38 39 40 41 42 43
      all_repos do |repo|
        if system(*cmd, chdir: repo)
          puts "Performed #{message} at #{repo}"
        else
          failures << repo
        end
44 45 46 47 48 49
      end

      failures
    end

    def output_failures(failures)
50
      puts "The following repositories reported errors:".color(:red)
51 52 53 54 55
      failures.each { |f| puts "- #{f}" }
    end

  end
end