Class: Blacksmith::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_blacksmith/git.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = '.') ⇒ Git

Returns a new instance of Git.



17
18
19
# File 'lib/puppet_blacksmith/git.rb', line 17

def initialize(path = '.')
  @path = File.expand_path(path)
end

Instance Attribute Details

#commit_message_patternObject

Pattern to use for tags, %s is replaced with the actual version



9
10
11
# File 'lib/puppet_blacksmith/git.rb', line 9

def commit_message_pattern
  @commit_message_pattern || '[blacksmith] Bump version to %s'
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#tag_message_patternObject

Returns the value of attribute tag_message_pattern.



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

def tag_message_pattern
  @tag_message_pattern
end

#tag_patternObject



13
14
15
# File 'lib/puppet_blacksmith/git.rb', line 13

def tag_pattern
  @tag_pattern || 'v%s'
end

#tag_signObject

Returns the value of attribute tag_sign.



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

def tag_sign
  @tag_sign
end

Instance Method Details

#commit_modulefile!(version) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/puppet_blacksmith/git.rb', line 45

def commit_modulefile!(version)
  files = Blacksmith::Modulefile::FILES.select { |f| File.exist?(File.join(@path, f)) }
  message = commit_message_pattern % version
  s = exec_git ['add'] + files
  s += exec_git ['commit', '-m', message]
  s
end

#has_tag?(tag) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/puppet_blacksmith/git.rb', line 21

def has_tag?(tag)
  exec_git(['tag', '--list', tag]).strip == tag
end

#has_version_tag?(version) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/puppet_blacksmith/git.rb', line 25

def has_version_tag?(version)
  tag = tag_pattern % version
  has_tag? tag
end

#push!Object



53
54
55
56
57
# File 'lib/puppet_blacksmith/git.rb', line 53

def push!
  s = exec_git ['push']
  s += exec_git ['push', '--tags']
  s
end

#tag!(version) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/puppet_blacksmith/git.rb', line 30

def tag!(version)
  tag = tag_pattern % version
  command = ['tag', tag]
  if tag_message_pattern
    tag_message = tag_message_pattern % version
    command += ['-m', tag_message]
  end
  if tag_sign
    raise Blacksmith::Error, 'Signed tags require messages - set tag_message_pattern' unless tag_message_pattern

    command += ['-s']
  end
  exec_git command
end