gitlab-org--gitlab-foss/lib/tasks/gitlab/update_gitignore.rake

47 lines
1.1 KiB
Ruby
Raw Normal View History

2016-04-29 10:25:03 -04:00
namespace :gitlab do
desc "GitLab | Update gitignore"
task :update_gitignore do
2016-05-12 07:27:25 -04:00
unless clone_gitignores
puts "Cloning the gitignores failed".color(:red)
2016-05-12 07:27:25 -04:00
return
end
2016-04-29 10:25:03 -04:00
2016-05-12 07:27:25 -04:00
remove_unneeded_files(gitignore_directory)
remove_unneeded_files(global_directory)
2016-04-29 10:25:03 -04:00
puts "Done".color(:green)
2016-04-29 10:25:03 -04:00
end
2016-05-12 07:27:25 -04:00
def clone_gitignores
FileUtils.rm_rf(gitignore_directory) if Dir.exist?(gitignore_directory)
FileUtils.cd vendor_directory
2016-04-29 10:25:03 -04:00
system('git clone --depth=1 --branch=master https://github.com/github/gitignore.git')
end
2016-05-12 07:27:25 -04:00
# 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/
2016-04-29 10:25:03 -04:00
end
end
2016-05-12 07:27:25 -04:00
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
2016-04-29 10:25:03 -04:00
end