Module: Berkshelf::Mixin::Git

Includes:
ShellOut
Included in:
GitLocation
Defined in:
lib/berkshelf/mixin/git.rb

Instance Method Summary collapse

Methods included from ShellOut

#shell_out, #shell_out!

Instance Method Details

#git(command, error = true, **kwargs) ⇒ Object

Perform a git command.

Parameters:

  • command (String)

    the command to run

  • error (Boolean) (defaults to: true)

    whether to raise error if the command fails

Raises:

  • (String)

    the $stdout from the command



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/berkshelf/mixin/git.rb', line 16

def git(command, error = true, **kwargs)
  unless Berkshelf.which("git") || Berkshelf.which("git.exe") || Berkshelf.which("git.bat")
    raise GitNotInstalled.new
  end

  response = shell_out(%{git #{command}}, **kwargs)

  if response.error?
    raise GitCommandError.new(command, cache_path, response.stderr)
  end

  response.stdout.strip
end