Class: RailsPwnerer::App::Git
- Inherits:
-
Object
- Object
- RailsPwnerer::App::Git
- Includes:
- Base
- Defined in:
- lib/rails_pwnerer/app/vcs/git.rb
Overview
checks out and updates the application from a Git repository
Instance Method Summary collapse
- #checkout(remote_path, app_name, instance_name) ⇒ Object
- #cleanup ⇒ Object
-
#cleanup_app_caches(app_name, instance_name, app_name_is_dir = false) ⇒ Object
clean up the application directory by removing caches.
-
#cleanup_app_dir(app_name, instance_name, target_dir, app_name_is_dir = false) ⇒ Object
remove any files not in Git in the application dir.
- #git_update(app_name, instance_name) ⇒ Object
-
#revert_config_changes(app_name, instance_name) ⇒ Object
reverts the config changes made by rpwn, so git fetch doesn’t get confused.
- #update(app_name, instance_name) ⇒ Object
- #update_prefetch(app_name, instance_name) ⇒ Object
Methods included from Base
_setup_unix, _setup_windows, all_packages, all_packages_without_caching, #atomic_erase, #atomic_read, #atomic_write, #best_package_matching, #check_rails_root, #control_boot_script, #cpu_cores, #current_user, #gem_exists?, #gid_for_username, #group_for_username, #hook_boot_script, #install_gem, #install_gems, #install_package, #install_package_impl, #install_package_matching, #install_packages, #kill_tree, #os_distro, package_info_hash, #path_to_boot_script, #path_to_boot_script_defaults, #path_to_gemdir, #process_info, #prompt_user_for_password, #remove_package, #remove_packages, #search_packages, #uid_for_username, #unroll_collection, #update_all_packages, #update_all_packages_impl, #update_gems, #update_package_metadata, #upgrade_gem, #upgrade_gems, #upgrade_package, #upgrade_package_impl, #upgrade_packages, #with_package_source, #with_temp_dir
Instance Method Details
#checkout(remote_path, app_name, instance_name) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rails_pwnerer/app/vcs/git.rb', line 71 def checkout(remote_path, app_name, instance_name) if hash_index = remote_path.rindex('#') git_repository = remote_path[0, hash_index] git_branch = remote_path[(hash_index + 1)..-1] else git_repository = remote_path git_branch = 'master' end return :next unless git_repository =~ /\.git(\/.*)?$/ app_path = RailsPwnerer::Config[app_name, instance_name][:app_path] FileUtils.rm_rf app_path print "Doing Git clone, please enter your password if prompted...\n" system "git clone -b #{git_branch} -- #{git_repository} #{app_path}" FileUtils.mkpath app_path unless File.exists? app_path # check that we really checked out a Rails app return check_rails_root(app_path) ? :ok : false end |
#cleanup ⇒ Object
67 68 69 |
# File 'lib/rails_pwnerer/app/vcs/git.rb', line 67 def cleanup # git checkout -- paths end |
#cleanup_app_caches(app_name, instance_name, app_name_is_dir = false) ⇒ Object
clean up the application directory by removing caches
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rails_pwnerer/app/vcs/git.rb', line 17 def cleanup_app_caches(app_name, instance_name, app_name_is_dir = false) # TODO: this is almost-duplicated in git.rb -- pull up somewhere app_path = app_name_is_dir ? app_name : RailsPwnerer::Config[app_name, instance_name][:app_path] return unless File.exists?(File.join(app_path, '.git')) # TODO: learn how Rails caches work and kill those too ['app', 'db', 'lib', 'public/images', 'public/javascripts', 'public/stylesheets', 'script', 'test', 'tmp', 'vendor', ].each { |dir| cleanup_app_dir app_name, instance_name, dir, app_name_is_dir } end |
#cleanup_app_dir(app_name, instance_name, target_dir, app_name_is_dir = false) ⇒ Object
remove any files not in Git in the application dir
7 8 9 10 11 12 13 14 |
# File 'lib/rails_pwnerer/app/vcs/git.rb', line 7 def cleanup_app_dir(app_name, instance_name, target_dir, app_name_is_dir = false) Dir.chdir(app_name_is_dir ? app_name : RailsPwnerer::Config[app_name, instance_name][:app_path]) do if File.exist?(target_dir) Kernel.system "git clean -d -f -x -- #{target_dir}" Kernel.system "git checkout -- #{target_dir}" end end end |
#git_update(app_name, instance_name) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/rails_pwnerer/app/vcs/git.rb', line 40 def git_update(app_name, instance_name) Dir.chdir RailsPwnerer::Config[app_name, instance_name][:app_path] do print "Doing Git pull, please enter your password if prompted...\n" Kernel.system 'git pull' end end |
#revert_config_changes(app_name, instance_name) ⇒ Object
reverts the config changes made by rpwn, so git fetch doesn’t get confused
30 31 32 33 34 35 36 37 38 |
# File 'lib/rails_pwnerer/app/vcs/git.rb', line 30 def revert_config_changes(app_name, instance_name) Dir.chdir RailsPwnerer::Config[app_name, instance_name][:app_path] do ['config', 'Gemfile', 'Gemfile.lock'].each do |dir| next unless File.exist?(dir) Kernel.system "git clean -d -f -x -- #{dir}" Kernel.system "git checkout -- #{dir}" end end end |
#update(app_name, instance_name) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/rails_pwnerer/app/vcs/git.rb', line 47 def update(app_name, instance_name) app_path = RailsPwnerer::Config[app_name, instance_name][:app_path] return unless File.exists?(File.join(app_path, '.git')) # TODO: maybe backup old version before issuing the git update? cleanup_app_caches app_name, instance_name revert_config_changes app_name, instance_name git_update app_name, instance_name end |
#update_prefetch(app_name, instance_name) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/rails_pwnerer/app/vcs/git.rb', line 57 def update_prefetch(app_name, instance_name) app_path = RailsPwnerer::Config[app_name, instance_name][:app_path] return unless File.exists?(File.join(app_path, '.git')) Dir.chdir app_path do print "Doing Git fetch, please enter your password if prompted...\n" Kernel.system 'git fetch origin' end end |