Last active
August 1, 2016 21:38
-
-
Save robertwahler/64c9c1fc52702a13212f32e9a5ffd1d0 to your computer and use it in GitHub Desktop.
Empty folders, #git, & #unity3d don't mix. Git doesn't track empty folders, why does @Unity3D?
This file contains hidden or 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 BasicUnity | |
class Code < Thor | |
namespace :code | |
include Thor::Actions | |
desc "prune", "Remove empty folders and Unity meta files that point to empty folders" | |
method_option "dry-run", :type => :boolean, :desc => "Show what will happen but don't 'rmdir' or 'rm'" | |
def prune(folder=nil) | |
# bash version, requires GNU find | |
# | |
# dry-run | |
# cmd = "find ./Assets -type d -empty -exec echo '{}' \; -exec echo '{}.meta' \;" | |
# run(cmd) | |
# | |
# for real | |
# cmd = "find ./Assets -type d -empty -exec rmdir '{}' \; -exec rm '{}.meta' \;" | |
# run(cmd) | |
# | |
folder = ASSETS_FOLDER unless folder | |
Dir.glob(File.join(folder, "**", "*")).select do |d| | |
File.directory?(d) | |
end.reverse_each do |d| | |
if ((Dir.entries(d) - %w[ . .. ]).empty?) | |
puts d | |
Dir.rmdir(d) unless options["dry-run"] | |
meta = "#{d}.meta" | |
if File.exist?(meta) | |
puts meta | |
File.delete(meta) unless options["dry-run"] | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment