class RailsPwnerer::App::Git

checks out and updates the application from a Git repository

Public Instance Methods

checkout(remote_path, app_name, instance_name) click to toggle source
   # File lib/rails_pwnerer/app/vcs/git.rb
71 def checkout(remote_path, app_name, instance_name)    
72   if hash_index = remote_path.rindex('#')
73     git_repository = remote_path[0, hash_index]
74     git_branch = remote_path[(hash_index + 1)..-1]
75   else
76     git_repository = remote_path
77     git_branch = 'master'
78   end
79   
80   return :next unless git_repository =~ /\.git(\/.*)?$/
81   app_path = RailsPwnerer::Config[app_name, instance_name][:app_path]
82   
83   FileUtils.rm_rf app_path
84   print "Doing Git clone, please enter your password if prompted...\n"
85   system "git clone -b #{git_branch} -- #{git_repository} #{app_path}"
86   FileUtils.mkpath app_path unless File.exists? app_path
87 
88   # check that we really checked out a Rails app
89   return check_rails_root(app_path) ? :ok : false
90 end
cleanup() click to toggle source
   # File lib/rails_pwnerer/app/vcs/git.rb
67 def cleanup
68   # git checkout -- paths
69 end
cleanup_app_caches(app_name, instance_name, app_name_is_dir = false) click to toggle source

clean up the application directory by removing caches

   # File lib/rails_pwnerer/app/vcs/git.rb
17 def cleanup_app_caches(app_name, instance_name, app_name_is_dir = false)
18   # TODO: this is almost-duplicated in git.rb -- pull up somewhere
19   app_path = app_name_is_dir ? app_name : RailsPwnerer::Config[app_name, instance_name][:app_path]
20   return unless File.exists?(File.join(app_path, '.git'))
21   
22   # TODO: learn how Rails caches work and kill those too
23   ['app', 'db', 'lib', 'public/images',
24   'public/javascripts', 'public/stylesheets', 'script',
25   'test', 'tmp', 'vendor',
26   ].each { |dir| cleanup_app_dir app_name, instance_name, dir, app_name_is_dir }
27 end
cleanup_app_dir(app_name, instance_name, target_dir, app_name_is_dir = false) click to toggle source

remove any files not in Git in the application dir

   # File lib/rails_pwnerer/app/vcs/git.rb
 7 def cleanup_app_dir(app_name, instance_name, target_dir, app_name_is_dir = false)
 8   Dir.chdir(app_name_is_dir ? app_name : RailsPwnerer::Config[app_name, instance_name][:app_path]) do
 9     if File.exist?(target_dir)
10       Kernel.system "git clean -d -f -x -- #{target_dir}"
11       Kernel.system "git checkout -- #{target_dir}"
12     end
13   end
14 end
git_update(app_name, instance_name) click to toggle source
   # File lib/rails_pwnerer/app/vcs/git.rb
40 def git_update(app_name, instance_name)
41   Dir.chdir RailsPwnerer::Config[app_name, instance_name][:app_path] do
42     print "Doing Git pull, please enter your password if prompted...\n"
43     Kernel.system 'git pull'
44   end
45 end
revert_config_changes(app_name, instance_name) click to toggle source

reverts the config changes made by rpwn, so git fetch doesn’t get confused

   # File lib/rails_pwnerer/app/vcs/git.rb
30 def revert_config_changes(app_name, instance_name)
31   Dir.chdir RailsPwnerer::Config[app_name, instance_name][:app_path] do
32     ['config', 'Gemfile', 'Gemfile.lock'].each do |dir|
33       next unless File.exist?(dir)
34       Kernel.system "git clean -d -f -x -- #{dir}"
35       Kernel.system "git checkout -- #{dir}"
36     end
37   end
38 end
update(app_name, instance_name) click to toggle source
   # File lib/rails_pwnerer/app/vcs/git.rb
47 def update(app_name, instance_name)
48   app_path = RailsPwnerer::Config[app_name, instance_name][:app_path]
49   return unless File.exists?(File.join(app_path, '.git'))
50   # TODO: maybe backup old version before issuing the git update?
51   
52   cleanup_app_caches app_name, instance_name    
53   revert_config_changes app_name, instance_name
54   git_update app_name, instance_name
55 end
update_prefetch(app_name, instance_name) click to toggle source
   # File lib/rails_pwnerer/app/vcs/git.rb
57 def update_prefetch(app_name, instance_name)
58   app_path = RailsPwnerer::Config[app_name, instance_name][:app_path]
59   return unless File.exists?(File.join(app_path, '.git'))
60   
61   Dir.chdir app_path do
62     print "Doing Git fetch, please enter your password if prompted...\n"
63     Kernel.system 'git fetch origin'
64   end
65 end