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.



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

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

Instance Attribute Details

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#commit_modulefile!Object



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

def commit_modulefile!
  files = Blacksmith::Modulefile::FILES.select {|f| File.exists?(File.join(@path,f))}
  s = exec_git "add #{files.join(" ")}"
  s += exec_git "commit -m '[blacksmith] Bump version'"
  s
end

#exec_git(cmd) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/puppet_blacksmith/git.rb', line 33

def exec_git(cmd)
  out = ""
  err = ""
  exit_status = nil
  new_cmd = git_cmd_with_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, err unless err.empty?
  elsif !exit_status.success?
    raise Blacksmith::Error, err.empty? ? "Command #{new_cmd} failed with exit status #{exit_status}#{"\n#{out}" unless out.empty?}" : err
  end
  return out
end

#git_cmd_with_path(cmd) ⇒ Object



29
30
31
# File 'lib/puppet_blacksmith/git.rb', line 29

def git_cmd_with_path(cmd)
  "git --git-dir=#{File.join(path, '.git')} --work-tree=#{path} #{cmd}"
end

#push!Object



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

def push!
  s = exec_git "push"
  s += exec_git "push --tags"
  s
end

#tag!(version) ⇒ Object



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

def tag!(version)
  exec_git "tag v#{version}"
end