Class: Paratrooper::SourceControl

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/paratrooper/source_control.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ SourceControl

Returns a new instance of SourceControl.



10
11
12
# File 'lib/paratrooper/source_control.rb', line 10

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



8
9
10
# File 'lib/paratrooper/source_control.rb', line 8

def config
  @config
end

Instance Method Details

#branch_nameObject



18
19
20
21
22
23
# 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_shaObject



33
34
35
# File 'lib/paratrooper/source_control.rb', line 33

def deployment_sha
  system_call("git rev-parse #{reference_point}").strip
end

#force_flagObject



37
38
39
# File 'lib/paratrooper/source_control.rb', line 37

def force_flag
  "-f " if config.force_push
end

#match_tag_nameObject



53
54
55
# File 'lib/paratrooper/source_control.rb', line 53

def match_tag_name
  config.match_tag_name
end

#push_to_deployObject



25
26
27
# 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_pointObject



29
30
31
# File 'lib/paratrooper/source_control.rb', line 29

def reference_point
  tag_name || branch_name || 'HEAD'
end

#remoteObject



14
15
16
# File 'lib/paratrooper/source_control.rb', line 14

def remote
  "git@#{config.deployment_host}:#{config.app_name}.git"
end

#scm_match_referenceObject



61
62
63
64
65
66
67
# 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_referenceObject



57
58
59
# 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) ⇒ Object

Internal: Calls commands meant to go to system.

cmd - String version of system command.



78
79
80
# File 'lib/paratrooper/source_control.rb', line 78

def system_call(cmd, exit_code = false)
  system_caller.execute(cmd, exit_code)
end

#tag_nameObject



41
42
43
# File 'lib/paratrooper/source_control.rb', line 41

def tag_name
  config.tag_name
end

#taggable?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/paratrooper/source_control.rb', line 45

def taggable?
  !untaggable?
end

#untaggable?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/paratrooper/source_control.rb', line 49

def untaggable?
  tag_name.nil? || tag_name.empty?
end

#update_repo_tagObject



69
70
71
72
# 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