Module: Berkshelf::Mixin::Git

Included in:
GitLocation, InitGenerator
Defined in:
lib/berkshelf/mixin/git.rb

Instance Method Summary collapse

Instance Method Details

#git(command, error = true) ⇒ 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



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

def git(command, error = true)
  unless Berkshelf.which('git') || Berkshelf.which('git.exe')
    raise GitNotInstalled.new
  end

  response = Buff::ShellOut.shell_out(%|git #{command}|)

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

  response.stdout.strip
end