summaryrefslogtreecommitdiff
path: root/lib/tasks/gitlab/update_gitignore.rake
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tasks/gitlab/update_gitignore.rake')
-rw-r--r--lib/tasks/gitlab/update_gitignore.rake46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/update_gitignore.rake b/lib/tasks/gitlab/update_gitignore.rake
new file mode 100644
index 00000000000..4fd48cccb1d
--- /dev/null
+++ b/lib/tasks/gitlab/update_gitignore.rake
@@ -0,0 +1,46 @@
+namespace :gitlab do
+ desc "GitLab | Update gitignore"
+ task :update_gitignore do
+ unless clone_gitignores
+ puts "Cloning the gitignores failed".color(:red)
+ return
+ end
+
+ remove_unneeded_files(gitignore_directory)
+ remove_unneeded_files(global_directory)
+
+ puts "Done".color(:green)
+ end
+
+ 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
+
+ # 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