class EY::Serverside::Slug::Source::Updater
Attributes
config[R]
git[R]
quiet[R]
ref[R]
source_cache[R]
uri[R]
Public Class Methods
new(input = {})
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 28 def initialize(input = {}) @input = input @config = input[:config] source = input[:config].source @source_cache = source.source_cache @uri = source.uri @quiet = source.opts[:verbose] ? '' : '--quiet' @ref = source.ref @git = "#{wrapped_git} --git-dir #{source_cache}/.git --work-tree #{source_cache}" end
Public Instance Methods
update()
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 39 def update call(@input) end
Private Instance Methods
calculate_requested_revision(input = {})
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 127 def calculate_requested_revision(input = {}) remote_branch = Dir.chdir(source_cache) do run_and_success?("#{git} show-branch origin/#{ref} > /dev/null 2>&1") end Success( input.merge( :requested_branch => remote_branch ? "origin/#{ref}" : ref ) ) end
checkout_requested_revision(input = {})
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 139 def checkout_requested_revision(input = {}) requested_branch = input[:requested_branch] Dir.chdir(source_cache) { run_and_success?( "git checkout --force #{quiet} '#{requested_branch}'" ) || run_and_success?( "git reset --hard #{quiet} '#{requested_branch}'" ) } ? Success(input) : Failure( input.merge(:error => "Could not check out #{requested_branch}") ) end
clean_local_branch(input = {})
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 121 def clean_local_branch(input = {}) run_and_success?("#{git} show-branch #{ref} > /dev/null 2>&1 && #{git} branch -D #{ref} > /dev/null 2>&1") Success(input) end
clean_source_cache(input = {})
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 175 def clean_source_cache(input = {}) return Failure( input.merge(:error => "Could not clean source") ) unless Dir.chdir(source_cache) { run_and_success?('git clean -dfq') } Success(input) end
clone_if_necessary(input = {})
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 92 def clone_if_necessary(input = {}) if input[:clone_needed] unless run_and_success?("rm -rf #{source_cache} && git clone #{quiet} #{uri} #{source_cache} 2>&1") return Failure( input.merge(:error => "Could not clone #{uri} to #{source_cache}") ) end end Success(input) end
create_source_cache(input = {})
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 49 def create_source_cache(input = {}) begin source_cache.mkpath rescue return Failure(:error => "Could not create #{source_cache}") end Success(input) end
determine_if_clone_needed(input = {})
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 83 def determine_if_clone_needed(input = {}) check = source_cache.directory? && run_and_output("#{git} remote -v | grep original").include?(uri) Success(input.merge(:clone_needed => !check)) end
ensure_ssh_wrapper(input = {})
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 59 def ensure_ssh_wrapper(input = {}) wrapper_location = paths.ssh_wrapper return Success(input) if File.executable?(wrapper_location) begin wrapper = File.open(wrapper_location, 'w', 0700) wrapper.write <<-WRAPPER #!/bin/sh unset SSH_AUTH_SOCK command=$(wcho "$*" | sed -e 's/^-batch //') ssh -o CheckHostIP=no -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o LogLevel=INFO -o IdentityFile=#{paths.deploy_key} -o IdentitiesOnly=yes ${command} WRAPPER wrapper.close rescue => e return Failure(input.merge(:error => e)) end Success(input) end
fetch_updates(input = {})
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 113 def fetch_updates(input = {}) return Failure( input.merge(:error => "Could not fetch #{source_cache}") ) unless run_and_success?("#{git} fetch --force --prune --update-head-ok #{quiet} origin '+refs/heads/*:refs/remotes/origin/*' '+refs/tags/*:refs/tags/*' 2>&1") Success(input) end
paths()
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 185 def paths config.paths end
prune_source_cache(input = {})
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 105 def prune_source_cache(input = {}) return Failure( input.merge(:error => "Could not prune #{source_cache}") ) unless run_and_success?("#{git} remote prune origin 2>&1") Success(input) end
sync_submodules(input = {})
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 155 def sync_submodules(input = {}) return Failure( input.merge(:error => "Could not sync submodules") ) unless Dir.chdir(source_cache) { run_and_success?("#{wrapped_git} submodule sync") } Success(input) end
update_submodules(input = {})
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 165 def update_submodules(input = {}) return Failure( input.merge(:error => "Could not update submodules") ) unless Dir.chdir(source_cache) { run_and_success?("#{wrapped_git} submodule update --init --recursive") } Success(input) end
wrapped_git()
click to toggle source
# File lib/engineyard-serverside/slug/source/updater.rb, line 45 def wrapped_git "GIT_SSH=#{paths.ssh_wrapper} git" end