Class: Bumpversion::GitOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/bumpversion/git_operation.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ GitOperation

Returns a new instance of GitOperation.



5
6
7
8
9
# File 'lib/bumpversion/git_operation.rb', line 5

def initialize(options)
  @options = options
  @git = Git.init
  Git.init('.')
end

Instance Method Details

#commit!Object



11
12
13
14
15
16
17
18
19
# File 'lib/bumpversion/git_operation.rb', line 11

def commit!
  if @options[:git_commit]
    PrettyOutput.info("git commit")
    file = @options[:file].split(',') + [@options[:config_file]]
    file += @options[:git_extra_add].split(',') if @options[:git_extra_add]
    @git.add(file)
    @git.commit("Bump version: #{@options[:current_version]} → #{@options[:new_version]}", {author: "#{@options[:git_user]} <#{@options[:git_email]}>"})
  end
end

#do!Object



40
41
42
43
44
# File 'lib/bumpversion/git_operation.rb', line 40

def do!
  commit!
  tag!
  push!
end

#push!Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bumpversion/git_operation.rb', line 28

def push!
  if @options[:git_push]
    @git.push
    if @options[:git_tag]
      PrettyOutput.info("git push with tags")
      @git.push(@git.remote.name, @git.branch.name, :tags => true)
    else
      PrettyOutput.info("git push")
    end
  end
end

#tag!Object



21
22
23
24
25
26
# File 'lib/bumpversion/git_operation.rb', line 21

def tag!
  if @options[:git_tag]
    PrettyOutput.info("git tag")
    @git.add_tag("v#{@options[:new_version]}")
  end
end