From 79620c501da19bfda5818b8dca75b6ec9c10e762 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Thu, 12 May 2016 13:27:25 +0200 Subject: Update API and fetching task --- lib/tasks/gitlab/update_gitignore.rake | 44 ++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'lib/tasks') diff --git a/lib/tasks/gitlab/update_gitignore.rake b/lib/tasks/gitlab/update_gitignore.rake index 61cbfd6737d..84aa312002b 100644 --- a/lib/tasks/gitlab/update_gitignore.rake +++ b/lib/tasks/gitlab/update_gitignore.rake @@ -1,26 +1,46 @@ namespace :gitlab do desc "GitLab | Update gitignore" task :update_gitignore do - dir = File.expand_path('vendor', Rails.root) - FileUtils.cd(dir) + unless clone_gitignores + puts "Cloning the gitignores failed".red + return + end - dir = File.expand_path('gitignore', dir) - clone_gitignores(dir) - remove_unneeded_files(dir) + remove_unneeded_files(gitignore_directory) + remove_unneeded_files(global_directory) puts "Done".green end - def clone_gitignores(dir) - FileUtils.rm_rf(dir) if Dir.exist?(dir) + def clone_gitignores + FileUtils.rm_rf(gitignore_directory) if Dir.exist?(gitignore_directory) + FileUtils.cd vendor_directory + system('git clone --depth=1 --branch=master https://github.com/github/gitignore.git') end - def remove_unneeded_files(dir) - [File.expand_path('Global', dir), dir].each do |path| - Dir.entries(path).reject { |e| e =~ /(\.{1,2}|Global|\.gitignore)\z/ }.each do |file| - FileUtils.rm_rf File.expand_path(file, path) - end + # Retain only certain files: + # - The LICENSE, because we have to + # - The sub dir global + # - The gitignores themself + # - Dir.entires returns also the entries '.' and '..' + def remove_unneeded_files(path) + Dir.foreach(path) do |file| + FileUtils.rm_rf(File.join(path, file)) unless file =~ /(\.{1,2}|LICENSE|Global|\.gitignore)\z/ end end + + private + + def vendor_directory + Rails.root.join('vendor') + end + + def gitignore_directory + File.join(vendor_directory, 'gitignore') + end + + def global_directory + File.join(gitignore_directory, 'Global') + end end -- cgit v1.2.3