BigW Consortium Gitlab

git.rake 1.28 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(git repack -a --quiet), "Repacking repo")
7 8 9 10 11 12 13
      if failures.empty?
        puts "Done".green
      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(git gc --auto --quiet), "Garbage Collecting")
17 18 19 20 21 22 23
      if failures.empty?
        puts "Done".green
      else
        output_failures(failures)
      end
    end
    
24
    desc "GitLab | Git | Prune all repos"
25
    task prune: :environment do
26
      failures = perform_git_cmd(%W(git prune), "Git Prune")
27 28 29 30 31 32 33 34 35 36 37
      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 = []
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 50 51 52 53 54 55
      end

      failures
    end

    def output_failures(failures)
      puts "The following repositories reported errors:".red
      failures.each { |f| puts "- #{f}" }
    end

  end
end