Created
January 4, 2010 16:46
-
-
Save chrisk/268645 to your computer and use it in GitHub Desktop.
Rails initializers that clean up git-submodule droppings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module EmptyDirectoryHelper | |
def self.dir_contains_files?(dir) | |
entries = Dir.entries(dir).reject { |entry| entry == '.' || entry == '..' } | |
entries.any? { |entry| !File.directory?(File.join(dir, entry)) || dir_contains_files?(File.join(dir, entry)) } | |
end | |
def self.empty_vendor_dirs | |
Dir.glob(Rails.root.join("vendor/{gems,plugins}/*")).reject { |dir| dir_contains_files?(dir) } | |
end | |
end | |
if %w(development test cucumber).include?(RAILS_ENV) # Only do this in local environments | |
empty = EmptyDirectoryHelper.empty_vendor_dirs | |
if empty.any? | |
puts | |
empty.each do |dir| | |
puts "Automatically deleting #{dir.sub(Rails.root.to_s + '/', '')}, since it only contains empty directories" | |
FileUtils.rm_rf dir | |
end | |
puts "You can probably ignore any 'config.gem: Unpacked gem' errors above.\n\n" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
paths = %w(vendor/gems/first_old_gem-0.1.0 | |
vendor/gems/second_old_gem-0.2.0) | |
paths.each do |path| | |
dir = Rails.root.join(path) | |
if File.directory?(dir) | |
puts "Automatically deleting #{dir.sub(Rails.root.to_s + '/', '')}, since it's an old submodule that we removed" | |
FileUtils.rm_rf dir | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment