Class: EY::Strategies::Git

Inherits:
Object show all
Includes:
LoggedOutput
Defined in:
lib/ey-deploy/strategies/git.rb

Defined Under Namespace

Modules: Helpers

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LoggedOutput

#debug, #info, logfile, logfile=, #logged_system, verbose=, verbose?, #verbose?

Constructor Details

#initialize(opts) ⇒ Git

Returns a new instance of Git.



42
43
44
45
# File 'lib/ey-deploy/strategies/git.rb', line 42

def initialize(opts)
  @opts = opts
  set_up_git_ssh(@opts[:app])
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



40
41
42
# File 'lib/ey-deploy/strategies/git.rb', line 40

def opts
  @opts
end

Instance Method Details

#checkoutObject



60
61
62
63
# File 'lib/ey-deploy/strategies/git.rb', line 60

def checkout
  info "~> Deploying revision #{short_log_message(to_checkout)}"
  logged_system("#{git} checkout -q '#{to_checkout}'") || logged_system("#{git} reset -q --hard '#{to_checkout}'")
end

#create_revision_file_command(dir) ⇒ Object



75
76
77
# File 'lib/ey-deploy/strategies/git.rb', line 75

def create_revision_file_command(dir)
  %Q{#{git} show --pretty=format:"%H" | head -1 > "#{dir}/REVISION"}
end

#fetchObject



51
52
53
54
55
56
57
58
# File 'lib/ey-deploy/strategies/git.rb', line 51

def fetch
  if usable_repository?
    logged_system("#{git} fetch -q origin 2>&1")
  else
    FileUtils.rm_rf(opts[:repository_cache])
    logged_system("git clone -q #{opts[:repo]} #{opts[:repository_cache]} 2>&1")
  end
end

#short_log_message(rev) ⇒ Object



79
80
81
# File 'lib/ey-deploy/strategies/git.rb', line 79

def short_log_message(rev)
  `#{git} log --pretty=oneline --abbrev-commit '#{rev}^..#{rev}'`.strip
end

#to_checkoutObject



65
66
67
68
69
70
71
72
73
# File 'lib/ey-deploy/strategies/git.rb', line 65

def to_checkout
  return @to_checkout if @opts_ref == opts[:ref]
  @opts_ref = opts[:ref]
  @to_checkout = if branch?(opts[:ref])
    "origin/#{opts[:ref]}"
  else
    opts[:ref]
  end
end

#usable_repository?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/ey-deploy/strategies/git.rb', line 47

def usable_repository?
  File.directory?(opts[:repository_cache]) && `#{git} remote -v | grep origin`[opts[:repo]]
end