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
- #create_revision_file_command(dir) ⇒ Object
- #fetch ⇒ Object
- #gc_repository_cache ⇒ Object
-
#initialize(shell, opts) ⇒ Git
constructor
A new instance of Git.
- #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.
7 8 9 10 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 7 def initialize(shell, opts) @shell = shell @opts = opts end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
5 6 7 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 5 def opts @opts end |
#shell ⇒ Object (readonly)
Returns the value of attribute shell.
5 6 7 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 5 def shell @shell end |
Instance Method Details
#checkout ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 31 def checkout shell.status "Deploying revision #{(to_checkout)}" in_repository_cache do (run("git checkout -q '#{to_checkout}'") || run("git reset -q --hard '#{to_checkout}'")) && run("git submodule sync") && run("git submodule update --init") && run("git clean -dfq") end end |
#create_revision_file_command(dir) ⇒ Object
53 54 55 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 53 def create_revision_file_command(dir) %Q{#{git} show --pretty=format:"%H" | head -1 > "#{dir}/REVISION"} end |
#fetch ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 22 def fetch if usable_repository? run("#{git} fetch -q origin 2>&1") else FileUtils.rm_rf(repository_cache) run("git clone -q #{remote_uri} #{repository_cache} 2>&1") end end |
#gc_repository_cache ⇒ Object
48 49 50 51 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 48 def gc_repository_cache shell.status "Garbage collecting cached git repository to reduce disk usage." run("#{git} gc") end |
#short_log_message(rev) ⇒ Object
57 58 59 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 57 def (rev) `#{git} log --pretty=oneline --abbrev-commit -n 1 '#{rev}'`.strip end |
#to_checkout ⇒ Object
42 43 44 45 46 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 42 def to_checkout return @to_checkout if @opts_ref == opts[:ref] @opts_ref = opts[:ref] @to_checkout = branch?(@opts_ref) ? "origin/#{@opts_ref}" : @opts_ref end |
#update_repository_cache ⇒ Object
12 13 14 15 16 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 12 def update_repository_cache unless fetch && checkout abort "*** [Error] Git could not checkout (#{to_checkout}) ***" end end |
#usable_repository? ⇒ Boolean
18 19 20 |
# File 'lib/engineyard-serverside/strategies/git.rb', line 18 def usable_repository? File.directory?(repository_cache) && `#{git} remote -v | grep origin`[remote_uri] end |