class Blacksmith::Git

Attributes

commit_message_pattern[RW]
path[RW]
tag_message_pattern[RW]
tag_pattern[RW]
tag_sign[RW]

Public Class Methods

new(path = ".") click to toggle source
# File lib/puppet_blacksmith/git.rb, line 26
def initialize(path = ".")
  @path = File.expand_path(path)
end

Public Instance Methods

commit_modulefile!(version) click to toggle source
# File lib/puppet_blacksmith/git.rb, line 53
def commit_modulefile!(version)
  files = Blacksmith::Modulefile::FILES.select {|f| File.exists?(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) click to toggle source
# File lib/puppet_blacksmith/git.rb, line 30
def has_tag?(tag)
  exec_git(['tag', '--list', tag]).strip == tag
end
has_version_tag?(version) click to toggle source
# File lib/puppet_blacksmith/git.rb, line 34
def has_version_tag?(version)
  tag = tag_pattern % version
  has_tag? tag
end
push!() click to toggle source
# File lib/puppet_blacksmith/git.rb, line 61
def push!
  s = exec_git ["push"]
  s += exec_git ["push", "--tags"]
  s
end
tag!(version) click to toggle source
# File lib/puppet_blacksmith/git.rb, line 39
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

Private Instance Methods

exec_git(cmd) click to toggle source
# File lib/puppet_blacksmith/git.rb, line 69
def exec_git(cmd)
  out = ""
  err = ""
  exit_status = nil
  new_cmd = ["git", "--git-dir", File.join(@path, '.git'), "--work-tree", @path] + cmd
  # wait_thr is nil in JRuby < 1.7.5 see http://jira.codehaus.org/browse/JRUBY-6409
  Open3.popen3(*new_cmd) do |stdin, stdout, stderr, wait_thr|
    out = stdout.read
    err = stderr.read
    exit_status = wait_thr.nil? ? nil : wait_thr.value
  end
  if exit_status.nil?
    raise Blacksmith::Error, "Command #{new_cmd} failed with stderr:\n#{err}#{"\nstdout:\n" + out unless out.empty?}" unless err.empty?
  elsif !exit_status.success?
    msg = err.empty? ? out : err
    msg = "\n#{msg}" unless msg.empty?
    raise Blacksmith::Error, "Command #{new_cmd} failed with exit status #{exit_status}#{msg}"
  end
  return out
end