Class: EY::Serverside::Strategies::Git
- Defined in:
- lib/engineyard-serverside/strategies/git.rb
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#shell ⇒ Object
readonly
Returns the value of attribute shell.
Instance Method Summary collapse
- #checkout ⇒ Object
- #clean_local_branch(ref) ⇒ Object
- #create_revision_file_command(dir) ⇒ Object
- #fetch ⇒ Object
- #gc_repository_cache ⇒ Object
-
#initialize(shell, opts) ⇒ Git
constructor
A new instance of Git.
-
#same?(previous_revision, active_revision, paths = nil) ⇒ Boolean
git diff --exit-code returns 0 when nothing has changed 1 when there are changes.
- #short_log_message(rev) ⇒ Object
- #to_checkout ⇒ Object
- #update_repository_cache ⇒ Object
- #usable_repository? ⇒ Boolean
Constructor Details
#initialize(shell, opts) ⇒ Git
Returns a new instance of Git.
9 10 11 12 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 9 def initialize(shell, opts) @shell = shell @opts = opts end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
7 8 9 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 7 def opts @opts end |
#shell ⇒ Object (readonly)
Returns the value of attribute shell.
7 8 9 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 7 def shell @shell end |
Instance Method Details
#checkout ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 32 def checkout shell.status "Deploying revision #{short_log_message(to_checkout)}" q = opts[:verbose] ? '' : '-q' in_repository_cache do (run("git checkout -f #{q} '#{to_checkout}'") || run("git reset --hard #{q} '#{to_checkout}'")) && run("git submodule sync") && run("git submodule update --init") && run("git clean -dfq") end end |
#clean_local_branch(ref) ⇒ Object
51 52 53 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 51 def clean_local_branch(ref) system("#{git} show-branch #{ref} > /dev/null 2>&1 && #{git} branch -D #{ref} > /dev/null 2>&1") end |
#create_revision_file_command(dir) ⇒ Object
60 61 62 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 60 def create_revision_file_command(dir) %Q{#{git} show --pretty=format:"%H" | head -1 > "#{dir}/REVISION"} end |
#fetch ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 24 def fetch if usable_repository? run("#{git} fetch -q origin 2>&1") else run("rm -rf #{repository_cache} && git clone -q #{remote_uri} #{repository_cache} 2>&1") end end |
#gc_repository_cache ⇒ Object
55 56 57 58 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 55 def gc_repository_cache shell.status "Garbage collecting cached git repository to reduce disk usage." run("#{git} gc") end |
#same?(previous_revision, active_revision, paths = nil) ⇒ Boolean
git diff --exit-code returns 0 when nothing has changed 1 when there are changes
Thes method returns true when nothing has changed, fales otherwise
73 74 75 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 73 def same?(previous_revision, active_revision, paths = nil) run("#{git} diff '#{previous_revision}'..'#{active_revision}' --exit-code --name-only -- #{Array(paths).join(' ')} >/dev/null 2>&1") end |
#short_log_message(rev) ⇒ Object
64 65 66 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 64 def (rev) `#{git} log --pretty=oneline --abbrev-commit -n 1 '#{rev}'`.strip end |
#to_checkout ⇒ Object
44 45 46 47 48 49 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 44 def to_checkout return @to_checkout if @opts_ref == opts[:ref] @opts_ref = opts[:ref] clean_local_branch(@opts_ref) @to_checkout = remote_branch?(@opts_ref) ? "origin/#{@opts_ref}" : @opts_ref end |
#update_repository_cache ⇒ Object
14 15 16 17 18 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 14 def update_repository_cache unless fetch && checkout abort "*** [Error] Git could not checkout (#{to_checkout}) ***" end end |
#usable_repository? ⇒ Boolean
20 21 22 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 20 def usable_repository? repository_cache.directory? && `#{git} remote -v | grep origin`[remote_uri] end |