module TerraspaceBundler::Util::Git

Public Instance Methods

git(command) click to toggle source
# File lib/terraspace_bundler/util/git.rb, line 21
def git(command)
  sh("git #{command}")
rescue TB::GitError => e
  action, version = command.split(' ')
  if action == "checkout" && version !~ /^v/
    command = "checkout v#{version}"
    retry
  else
    logger.error "ERROR: There was a git error".color(:red)
    logger.error "Current dir: #{Dir.pwd}"
    logger.error "The error occur when running:"
    logger.error e.message
  end
  exit 1
end
sh(command) click to toggle source
# File lib/terraspace_bundler/util/git.rb, line 5
def sh(command)
  command = "#{command} 2>&1" # always need output for the sha
  logger.debug "=> #{command}"
  out = `#{command}`
  unless $?.success?
    if command.include?("git")
      raise TB::GitError.new("#{command}\n#{out}")
    else
      logger.error "ERROR: running #{command}".color(:red)
      logger.error out
      exit $?.exitstatus
    end
  end
  out
end