class Paratrooper::SourceControl

Attributes

config[RW]

Public Class Methods

new(config) click to toggle source
# File lib/paratrooper/source_control.rb, line 10
def initialize(config)
  @config = config
end

Public Instance Methods

branch_name() click to toggle source
# File lib/paratrooper/source_control.rb, line 18
def branch_name
  if config.branch_name?
    branch = config.branch_name.to_s
    branch.upcase == "HEAD" ? "HEAD" : "refs/heads/#{config.branch_name}"
  end
end
deployment_sha() click to toggle source
# File lib/paratrooper/source_control.rb, line 33
def deployment_sha
  system_call("git rev-parse #{reference_point}").strip
end
force_flag() click to toggle source
# File lib/paratrooper/source_control.rb, line 37
def force_flag
  "-f " if config.force_push
end
match_tag_name() click to toggle source
# File lib/paratrooper/source_control.rb, line 53
def match_tag_name
  config.match_tag_name
end
push_to_deploy() click to toggle source
# File lib/paratrooper/source_control.rb, line 25
def push_to_deploy
  system_call("git push #{force_flag}#{remote} #{reference_point}:refs/heads/master", :exit_code)
end
reference_point() click to toggle source
# File lib/paratrooper/source_control.rb, line 29
def reference_point
  tag_name || branch_name || 'HEAD'
end
remote() click to toggle source
# File lib/paratrooper/source_control.rb, line 14
def remote
  "git@#{config.deployment_host}:#{config.app_name}.git"
end
scm_match_reference() click to toggle source
# File lib/paratrooper/source_control.rb, line 61
def scm_match_reference
  if match_tag_name
    "refs/tags/#{match_tag_name}"
  else
    "HEAD"
  end
end
scm_tag_reference() click to toggle source
# File lib/paratrooper/source_control.rb, line 57
def scm_tag_reference
  "refs/tags/#{tag_name}" if tag_name
end
system_call(cmd, exit_code = false) click to toggle source

Internal: Calls commands meant to go to system.

cmd - String version of system command.

# File lib/paratrooper/source_control.rb, line 78
def system_call(cmd, exit_code = false)
  system_caller.execute(cmd, exit_code)
end
tag_name() click to toggle source
# File lib/paratrooper/source_control.rb, line 41
def tag_name
  config.tag_name
end
taggable?() click to toggle source
# File lib/paratrooper/source_control.rb, line 45
def taggable?
  !untaggable?
end
untaggable?() click to toggle source
# File lib/paratrooper/source_control.rb, line 49
def untaggable?
  tag_name.nil? || tag_name.empty?
end
update_repo_tag() click to toggle source
# File lib/paratrooper/source_control.rb, line 69
def update_repo_tag
  system_call("git tag #{tag_name} #{match_tag_name} -f")
  system_call("git push -f origin #{scm_tag_reference}")
end