namespace 'rails' do desc 'Remove rails tmp dirs' task 'rm_tmp_dirs' do ["./tmp/pids", "./tmp/sessions", "./tmp/sockets", "./tmp/cache"].each do |f| system("rmdir ./#{f}") end end end namespace 'git' do desc 'Add a .gitignore to empty directories to allow them to be committed to Git' task 'hold_empty_dirs' do system("find . \\( -type d -empty \\) -and \\( -not -regex ./\\.git.* \\) -exec touch {}/.gitignore \\;") end desc 'Update git submodules' task 'update_submodules' do system("git submodule init") system("git submodule update") system("git status") end desc 'Track branch master' task 'track_master' do system('echo -e [branch \"master\"]\\\n\\\tremote = origin\\\n\\\tmerge = refs/heads/master >> ./.git/config') end namespace 'hub' do task 'add_origin' do app = File.basename(Dir.getwd) system("git remote add origin git@github.com:cwsaylor/#{app}.git") end namespace 'rails' do desc 'Configure current Rails app for Github.' task 'new_app' => ['git:rails:new_app', 'git:hub:add_origin', 'git:track_master'] do system("git push origin master") end end end namespace 'rails' do desc 'Configure a new Rails app for Git. cd rails_app first.' task 'new_app' => ['rails:rm_tmp_dirs', 'git:hold_empty_dirs'] do system("git init") system("touch .gitignore") ["log/\\*.log", "log/\\*.pid", "db/\\*.db", "db/\\*.sqlite3", "db/schema.rb", "tmp/\\*\\*/\\*", ".DS_Store", "doc/api", "doc/app", "config/database.yml"].each do |entry| system("echo #{entry} >> .gitignore") end system("cp config/database.yml config/database.example.yml") system("git add .") system("git commit -m 'Setting up a new rails app. Copy config/database.example.yml to config/database.yml and customize.'") end desc 'Clone Rails into vendor/rails from github' task 'clone' do system("git clone git://github.com/rails/rails.git vendor/rails") end desc 'Export Rails into vendor/rails from github' task 'export' => ['git:rails:clone'] do system("rm -rf ./vendor/rails/.git") end desc 'Add Rails as a git submodule' task 'submodule' do system("git submodule add git://github.com/rails/rails.git vendor/rails") system("git commit -m 'Adding Rails as a submodule.' .gitmodules vendor/rails") end end end