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
64
65
66
67
68
# File 'lib/ey-deploy/strategies/git.rb', line 60

def checkout
  info "~> Deploying revision #{short_log_message(to_checkout)}"
  in_git_work_tree do
    (logged_system("git checkout -q '#{to_checkout}'") ||
      logged_system("git reset -q --hard '#{to_checkout}'")) &&
      logged_system("git submodule update --init") &&
      logged_system("git clean -dfq")
  end
end

#create_revision_file_command(dir) ⇒ Object



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

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



84
85
86
# File 'lib/ey-deploy/strategies/git.rb', line 84

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

#to_checkoutObject



70
71
72
73
74
75
76
77
78
# File 'lib/ey-deploy/strategies/git.rb', line 70

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