Class: Chap::Strategy::Checkout

Inherits:
Base
  • Object
show all
Includes:
Benchmarking
Defined in:
lib/chap/strategy/checkout.rb

Direct Known Subclasses

Hardlink

Constant Summary

Constants included from Chap::SpecialMethods

Chap::SpecialMethods::SPECIAL_METHODS

Instance Attribute Summary

Attributes inherited from Base

#config, #options

Instance Method Summary collapse

Methods included from Benchmarking

#benchmarks, included, #report_benchmarks, #shorten_name

Methods inherited from Base

#initialize

Methods included from Chap::SpecialMethods

included

Constructor Details

This class inherits a constructor from Chap::Strategy::Base

Instance Method Details

#checkoutObject



33
34
35
36
37
38
39
40
# File 'lib/chap/strategy/checkout.rb', line 33

def checkout
  command =<<BASH
  git clone -q #{config.chap[:repo]} #{cached_path} && \
  cd #{cached_path} && \
  git checkout -q -b deploy #{revision}
BASH
  run(command)
end

#copyObject



42
43
44
45
46
# File 'lib/chap/strategy/checkout.rb', line 42

def copy
  command = "cp -RPp #{cached_path} #{release_path} && #{mark}"
  run command
  log "Code copied to #{release_path}".colorize(:green)
end

#deployObject



6
7
8
9
# File 'lib/chap/strategy/checkout.rb', line 6

def deploy
  update
  copy
end

#syncObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/chap/strategy/checkout.rb', line 22

def sync
  command =<<-BASH
cd #{cached_path} &&  \
git fetch -q origin && \
git fetch --tags -q origin && \
git reset -q --hard #{revision} && \
git clean -q -d -x -f
BASH
  run(command)
end

#updateObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/chap/strategy/checkout.rb', line 11

def update
  log "Updating repo in #{cached_path}".colorize(:green)
  cached_root = File.dirname(cached_path)
  FileUtils.mkdir_p(cached_root) unless File.exist?(cached_root)
  if File.exist?(cached_path)
    sync
  else
    checkout
  end
end