cwsaylor (owner)

Forks

Revisions

gist: 6750 Download_button fork
public
Description:
Git sake tasks
Public Clone URL: git://gist.github.com/6750.git
Sakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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