class ChefCLI::Policyfile::ComparisonBase::Git

Attributes

policyfile_lock_relpath[R]
ref[R]

Public Class Methods

new(ref, policyfile_lock_relpath) click to toggle source
# File lib/chef-cli/policyfile/comparison_base.rb, line 58
def initialize(ref, policyfile_lock_relpath)
  @ref = ref
  @policyfile_lock_relpath = policyfile_lock_relpath
end

Public Instance Methods

git_cmd() click to toggle source
# File lib/chef-cli/policyfile/comparison_base.rb, line 77
def git_cmd
  @git_cmd ||= Mixlib::ShellOut.new(git_cmd_string)
end
git_cmd_string() click to toggle source
# File lib/chef-cli/policyfile/comparison_base.rb, line 81
def git_cmd_string
  # Git is a little picky about how we specify the paths, but it looks
  # like we don't need to worry about the relative path to the root of
  # the repo if we give git a leading dot:
  #
  #    git show 6644e6cb2ade90b8aff2ebb44728958fbc939ebf:zero.rb
  #    fatal: Path 'etc/zero.rb' exists, but not 'zero.rb'.
  #    Did you mean '6644e6cb2ade90b8aff2ebb44728958fbc939ebf:etc/zero.rb' aka '6644e6cb2ade90b8aff2ebb44728958fbc939ebf:./zero.rb'?
  #    git show 6644e6cb2ade90b8aff2ebb44728958fbc939ebf:./zero.rb
  #    (works)
  "git show #{ref}:./#{policyfile_lock_relpath}"
end
lock() click to toggle source
# File lib/chef-cli/policyfile/comparison_base.rb, line 67
def lock
  git_cmd.run_command
  git_cmd.error!
  FFI_Yajl::Parser.parse(git_cmd.stdout)
rescue Mixlib::ShellOut::ShellCommandFailed
  raise GitError, "Git command `#{git_cmd_string}` failed with message: #{git_cmd.stderr.chomp}"
rescue FFI_Yajl::ParseError => e
  raise MalformedLockfile, "Invalid JSON in lockfile at git ref '#{ref}' at path '#{policyfile_lock_relpath}':\n  #{e.message}"
end
name() click to toggle source
# File lib/chef-cli/policyfile/comparison_base.rb, line 63
def name
  "git:#{ref}"
end