Class: StiDeploy::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/sti_deploy/git.rb,
lib/sti_deploy/git/merge.rb,
lib/sti_deploy/git/commit.rb

Defined Under Namespace

Classes: Commit, Merge

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, deploy_type) ⇒ Git

Returns a new instance of Git.



41
42
43
44
# File 'lib/sti_deploy/git.rb', line 41

def initialize(version, deploy_type)
  @version = version
  @deploy_type = deploy_type
end

Instance Attribute Details

#deploy_typeObject (readonly)

Returns the value of attribute deploy_type.



5
6
7
# File 'lib/sti_deploy/git.rb', line 5

def deploy_type
  @deploy_type
end

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/sti_deploy/git.rb', line 5

def version
  @version
end

Class Method Details

.add_versionObject



8
9
10
# File 'lib/sti_deploy/git.rb', line 8

def add_version
  `git add #{Configuration.version_path}`
end

.checkout(branch: 'master') ⇒ Object



16
17
18
# File 'lib/sti_deploy/git.rb', line 16

def checkout(branch: 'master')
  `git checkout #{branch}`.to_i.zero?
end

.commit(message: '') ⇒ Object



12
13
14
# File 'lib/sti_deploy/git.rb', line 12

def commit(message: '')
  `git commit -m "#{message.tr('"', '\"')}"`.to_i.zero?
end

.merge(branch: 'master') ⇒ Object



20
21
22
# File 'lib/sti_deploy/git.rb', line 20

def merge(branch: 'master')
  `git merge #{branch}`.to_i.zero?
end

.pull(branch: 'master', remote: 'origin') ⇒ Object



28
29
30
# File 'lib/sti_deploy/git.rb', line 28

def pull(branch: 'master', remote: 'origin')
  `git pull #{remote} #{branch}`.to_i.zero?
end

.push(branch: 'master', remote: 'origin') ⇒ Object



32
33
34
# File 'lib/sti_deploy/git.rb', line 32

def push(branch: 'master', remote: 'origin')
  `git push #{remote} #{branch}`.to_i.zero?
end

.push_tagsObject



36
37
38
# File 'lib/sti_deploy/git.rb', line 36

def push_tags
  `git push --tags`.to_i.zero?
end

.tag(version: '', message: '') ⇒ Object



24
25
26
# File 'lib/sti_deploy/git.rb', line 24

def tag(version: '', message: '')
  `git tag -a v#{version.to_s} -m "#{message.tr('"', '\"')}"`.to_i.zero?
end

Instance Method Details

#commit!(message) ⇒ Object



52
53
54
# File 'lib/sti_deploy/git.rb', line 52

def commit!(message)
  Git::Commit.new(commit_branch, message).commit!
end

#commit_branchObject



68
69
70
# File 'lib/sti_deploy/git.rb', line 68

def commit_branch
  Configuration.commit_branch(deploy_type)
end

#commit_merge_and_tag!(message) ⇒ Object



46
47
48
49
50
# File 'lib/sti_deploy/git.rb', line 46

def commit_merge_and_tag!(message)
  commit!(message)
  merge!
  tag!(message)
end

#merge!Object



56
57
58
59
60
# File 'lib/sti_deploy/git.rb', line 56

def merge!
  merge_branches.each do |target_branch|
    Git::Merge.new(commit_branch, target_branch).merge!
  end
end

#merge_branchesObject

Can be more than one branch, example: merge staging to production and hotfix, to synchronize production with hotfix and staging.



74
75
76
# File 'lib/sti_deploy/git.rb', line 74

def merge_branches
  Array(Configuration.merge_branch(deploy_type))
end

#tag!(message) ⇒ Object



62
63
64
65
66
# File 'lib/sti_deploy/git.rb', line 62

def tag!(message)
  Messages.puts('git.tagging', color: :yellow)
  Git.tag(version: version.to_s, message: message)
  Git.push_tags
end