Class: Deliv::Deploy::Git
- Inherits:
-
Object
- Object
- Deliv::Deploy::Git
- Defined in:
- lib/deliv/deploy/git.rb
Instance Attribute Summary collapse
-
#release_branch ⇒ Object
Returns the value of attribute release_branch.
-
#release_remote ⇒ Object
Returns the value of attribute release_remote.
-
#release_tag ⇒ Object
Returns the value of attribute release_tag.
-
#source_branch ⇒ Object
Returns the value of attribute source_branch.
-
#source_remote ⇒ Object
Returns the value of attribute source_remote.
Instance Method Summary collapse
- #current_branch ⇒ Object
- #deploy ⇒ Object
-
#initialize(environment) ⇒ Git
constructor
A new instance of Git.
- #print_debug ⇒ Object
- #user_name ⇒ Object
Constructor Details
#initialize(environment) ⇒ Git
Returns a new instance of Git.
6 7 8 9 10 11 12 13 |
# File 'lib/deliv/deploy/git.rb', line 6 def initialize(environment) @environment = environment @source_remote = 'origin' @source_branch = current_branch @release_remote = 'upstream' @release_branch = "release-#{@environment}" @release_tag = "#{@release_branch}-#{Time.current.to_i}" end |
Instance Attribute Details
#release_branch ⇒ Object
Returns the value of attribute release_branch.
4 5 6 |
# File 'lib/deliv/deploy/git.rb', line 4 def release_branch @release_branch end |
#release_remote ⇒ Object
Returns the value of attribute release_remote.
4 5 6 |
# File 'lib/deliv/deploy/git.rb', line 4 def release_remote @release_remote end |
#release_tag ⇒ Object
Returns the value of attribute release_tag.
4 5 6 |
# File 'lib/deliv/deploy/git.rb', line 4 def release_tag @release_tag end |
#source_branch ⇒ Object
Returns the value of attribute source_branch.
4 5 6 |
# File 'lib/deliv/deploy/git.rb', line 4 def source_branch @source_branch end |
#source_remote ⇒ Object
Returns the value of attribute source_remote.
4 5 6 |
# File 'lib/deliv/deploy/git.rb', line 4 def source_remote @source_remote end |
Instance Method Details
#current_branch ⇒ Object
28 29 30 |
# File 'lib/deliv/deploy/git.rb', line 28 def current_branch `git rev-parse --abbrev-ref HEAD`&.squish end |
#deploy ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/deliv/deploy/git.rb', line 15 def deploy print_debug old_branch = current_branch `git commit --all --message='Saving before #{release_tag}'` `git push #{source_remote} #{source_branch}` `git fetch #{source_remote} #{source_branch}` `git checkout --quiet #{source_remote}/#{source_branch}` `git tag --message='#{user_name} pointed #{release_branch} at #{current_branch}' #{release_tag}` `git push --force --follow-tags #{release_remote} HEAD:#{release_branch}` `git checkout #{old_branch}` end |
#print_debug ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/deliv/deploy/git.rb', line 36 def print_debug puts "User Name: #{user_name}".blue puts "Current Branc: #{current_branch}".blue puts "Source Remote: #{source_remote}".blue puts "Source Branch: #{source_branch}".blue puts "Release Remote: #{release_remote}".blue puts "Release Branch: #{release_branch}".blue end |
#user_name ⇒ Object
32 33 34 |
# File 'lib/deliv/deploy/git.rb', line 32 def user_name `git config --get user.name`&.squish end |